Can i concatenate a string variable into a form control call?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew Kennedy

    #1

    Can i concatenate a string variable into a form control call?

    I'm not quite a noob, but I'm self taught and so I have some holes in my coding skills. I know that this should be possible but i cannot figure out what the syntax is. this is my first post to any forum and I'm only doing it because I have searched for the answer for days now, so forgive me of any posting faux pas.

    Anyway, I have a parent form with 8 subforms that toggle visibility on top of one another depending on criteria in the parent.

    I am setting a public string variable in the toggling function with the parent and subform name like so:
    Code:
    Forms![ProductShipment]![frmShipmentScaleDataSubform].Form.Visible = True
    strCurrentForm = "Forms![ProductShipment]![frmShipmentScaleDataSubform].Form"
    Then I'm trying to combine that variable with the form control to call it like this (which yes I know is wrong):
    Code:
    If strCurrentForm!txtNetWeight.Visible = False Then
    The "me" technique can only replace the parent name and not the subform so that doen't help because it's the constant toggling of visible subforms that is causing the problem. If I can't find a work around I'll have to write 8 times more code for every "If" statement.

    Thanks ahead of time for any help.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    I suspect you may be overcomplicatin g this (and Me is indeed something to use in your code). Check out Referring to Items on a Sub-Form and see if that doesn't help you to resolve this more easily.

    If not, come back and I'll see what I can do to provide more specific help.

    Welcome to Bytes!

    Comment

    • Matthew Kennedy

      #3
      Wow...quick response.
      NeoPa you have helped me with your posts more than you could know. And I have read the linked page you suggested again, but even in it there is clearly no way to replace the subform name with "Me".

      This is a scaling system that has basicly two events(material s in adn product out). So there are only a few parent forms but I have 8 subforms (on each parent) that share a lot of the same controls. My code is already thousands of lines to make it work. This is to simplify the control name calls.

      It's like an attempt at a "Current visible subform" variable.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        Originally posted by Matthew Kennedy
        Matthew Kennedy:
        It's like an attempt at a "Current visible subform" variable.
        As usual then, the devil is in the detail. I assume you have some code that wants to refer to the active sub-form, from the main form (The code is in the main form's module), but you are struggling to determine which sub-form is currently active?

        I would think that you should be looking at Me.ActiveContro l for a starting-point if that's the case.

        I don't have a database with any sub-forms to play with, so I can't do too much testing on this, but if you're still struggling and would like me to look at your database for you then I could do that, but only for registered members (The risks of dealing with anonymous users' work is too high for me). I'm happy to help anonymous users where I can, but opening attachments is another matter.

        If you choose to go this route then first register (of course), then here are some other useful instructions to follow before attaching your database :

        When attaching your work please follow the following steps first :
        1. Remove anything not relevant to the problem. This is not necessary in all circumstances but some databases can be very bulky and some things do not effect the actual problem at all.
        2. Likewise, not entirely necessary in all cases, but consider saving your database in a version not later than 2003 as many of our experts don't use Access 2007. Largely they don't want to, but some also don't have access to it. Personally I will wait until I'm forced to before using it.
        3. If the process depends on any linked tables then make local copies in your database to replace the linked tables.
        4. If the database includes any code, ensure that all modules are set to Option Explicit (See Require Variable Declaration).
        5. If you've done anything in steps 1 to 4 then make sure that the problem you're experiencing is still evident in the updated version.
        6. Compile the database (From the Visual Basic Editor select Debug / Compile {Project Name}).
        7. Compact the database (Tools / Database Utilities / Compact and Repair Database...).
        8. Compress the database into a ZIP file.
        9. When posting, scroll down the page and select Manage Attachments (Pressing on that leads you to a page where you can add or remove your attachments. It also lists the maximum file sizes for each of the allowed file types.) and add this new ZIP file.

        It's also a good idea to include some instructions that enable us to find the issue you'd like help with. Maybe some instructions of what to select, click on, enter etc that ensures we'll see what you see and have the same problems.

        Comment

        Working...