Results 1 to 3 of 3
  1. #1
    dcdimon's Avatar
    dcdimon is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Bradenton, FL
    Posts
    71

    Make subform control reference with a string

    Greetings,



    Once again I find myself tantalizingly close to an answer but unable to get all the way there without help. Or at least without someone saying "it can't be done".

    I'm trying to reference a control on a subform so I can auto-fill it based on a control on the main form. I am well versed in how to do this when typing the specific pointers, however, what I'm trying to do is build the pointer through strings. The controls on my main form and subform are similarly named, with the last three characters being different.

    I have a controls on the main form titled ControliTxt (where i is a number 1-10). The subform controls are titled ControliOOR (again i is a number 1 - 10) The subform controls are used to indicate if the data in the main form is within the data range for that control and the numbers on the main form control coincide with the subform control number (Control1Txt goes with Control1OOR).

    I should also add that my form controls, both main and sub, are dynamic. Meaning that what they measure, the ranges, and the control source changes as different fields are picked via another form. The control names don't change, but what they're measuring does. Which is why I'm looking for coding solution that can pull names and point to controls based on the current control and not hard wiring that information.

    I'm trying to create a module that looks at the active control's name (Control1Txt) and use that to work out the subform control's name, something like this:

    Code:
    Forms!DynamicDataTest!Compliancesubform.form.Control1OOR
    I can build this as a string by cropping the last three characters of the Screen.ActiveControl.Name property and inserting the OOR ending for the subform using this:

    Code:
    Ctl = "forms!dynamicdataformcopy!compliancesubform.form." & Left(Screen.ActiveControl.Name, Len(Screen.ActiveControl.Name) - 3) & "OOR"
    My problem comes that I don't know how to use this string to insert a value into this control. I've also tried building the pointer using the components of the string (see below), but as you may expect, the VBA editor doesn't know what to do with all the separate parts.

    Code:
    forms!dynamicdataformcopy!compliancesubform.form. & Left(Screen.ActiveControl.Name, Len(Screen.ActiveControl.Name) - 3) & "OOR"
    I'm thinking that I'm missing the proper use of quotes and the '&' symbol in putting this together. And/or that I'm trying to use the string in the incorrect way. Or that I'm barking up the wrong tree.

    Any help would be appreciated.

    DD

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I have programmatically constructed control name like:

    Forms(Me.Name).Controls("tbxPost" & i).Value

    So maybe in your case:

    Forms!dynamicdataformcopy!compliancesubform.Form.C ontrols(Left(Screen.ActiveControl.Name, Len(Screen.ActiveControl.Name) - 3) & "OOR").Value
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    dcdimon's Avatar
    dcdimon is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Bradenton, FL
    Posts
    71
    Woohoo!!!!!! It works!!!

    Thank you June7, I knew there was a way to do this, but I couldn't think of how to put it together. I would have never stumbled upon the parenthesis usage on my own. I have spent hours today searching for how to do this - I should have just posted my question right away and I'd be farther along on my project.

    Thank you again. You are the best!

    DD

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 10-07-2013, 12:27 PM
  2. Replies: 3
    Last Post: 03-29-2012, 12:40 PM
  3. Replies: 3
    Last Post: 01-05-2012, 10:47 AM
  4. Replies: 1
    Last Post: 05-12-2011, 02:25 PM
  5. Can't reference control in subform
    By evanscamman in forum Forms
    Replies: 0
    Last Post: 12-25-2007, 06:47 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums