Results 1 to 4 of 4
  1. #1
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200

    Assign value to variable on other form

    I have set a "form-wide" variable on a certain form to contain integers. I want to populate this variable from a subform located on this form.

    So, for example, if the form has an integer for CompanyID, I want to populate this variable from the subform so that when I am back on the main form I can use this variable with the populated variable. What is the syntax for this?

  2. #2
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    The syntax differs depending on where you have the code, the main form or the subform.

    You can use something like this, from the main form:

    Me![controlname1]= me![subformcontrolname].form.[controlname2]

    where:

    [controlname1] is the name of the main form control to receive the value
    [subformcontrolname] is the name of the control containing the subform
    [controlname2] is the name of the control on the subform containing the value you want.

    Note that you do not use the actual name of the subform!

    From within the subform, the syntax is:

    Me.parent![controlname1] = me![controlname2], with the meanings the same.

    Which of the two you use will depend on what you need to do.

    HTH

    John

  3. #3
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200
    Yes, I'm able to reference controls on the main form from a subform just fine. But what I am trying to do is reference not a control, but a string variable that is declared at the form level.

  4. #4
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    I have not tried this (reference a variable in a subform), but I have referenced a variable in a main form. I can't guarantee it will work, but try this:

    Declare the variable in the subform as Public (in the declarations section) : Public variablename as String

    Then, reference it from the main form as : me!subformcontrolname.form.variablename

    HTH

    John

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

Similar Threads

  1. Replies: 1
    Last Post: 04-25-2013, 02:52 PM
  2. can't assign a new value to a form field
    By markjkubicki in forum Programming
    Replies: 4
    Last Post: 09-28-2012, 08:03 PM
  3. Replies: 3
    Last Post: 03-28-2012, 10:16 AM
  4. Refering to variable form names inside a variable
    By redpetfran in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 01:39 PM
  5. Assign and call variable from table
    By smikkelsen in forum Access
    Replies: 7
    Last Post: 04-01-2010, 09:38 AM

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