Results 1 to 4 of 4
  1. #1
    Nokia N93 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    55

    Pass Variable Values From One Form to Another

    i have two forms , and one table
    i want when i enter the first form and press Next or Submit, i want specific values to be passed to the next form (example ID, name, and address)
    i knew there is something called OpenArgs but i didn't know how to apply it, i also read it is just for one value



  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    I never use openargs, but it is very useful. if the 1st form is still open when you open the second, you can always grab vals from it directly, like so:
    Code:
    me.control = forms!firstform!control

  3. #3
    Nokia N93 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    55
    Quote Originally Posted by ajetrumpet View Post
    I never use openargs, but it is very useful. if the 1st form is still open when you open the second, you can always grab vals from it directly, like so:
    Code:
    me.control = forms!firstform!control
    thanx but i'm afraid that the users -sometimes- may close the first form :S

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Nokia N93 View Post
    i have two forms , and one table
    i want when i enter the first form and press Next or Submit, i want specific values to be passed to the next form (example ID, name, and address)
    i knew there is something called OpenArgs but i didn't know how to apply it, i also read it is just for one value
    There are several ways to accomplish what you want to do. So here is the setup;

    There is one table, "Table1", and two forms, "Form_A" and FormB" (notice - no spaces). At this point I have to wonder "Why two forms?". The data is stored in Table1, so one form could display the data.

    Moving on..

    Method 1: referring to controls on a previous form (as Adam posted).

    Method 2: Use the "WhereCondition" argument of the "OpenForm" method. (IMO,the easiest method)
    If the "ID" field type is a number, the command would look like"

    Code:
    DoCmd.OpenForm "FormB", , ,"ID = " & Me.tbID
    (tb=text box)

    This would open the form "FormB" to the first record that equaled the number in the control "tbID" on form "Form_A". The (new) record on "Form_A" must be saved first.

    Method 3: Use OpenArgs

    This takes some coding. And you can pass more than one value, but it requires code. The command would look like:

    Code:
    DoCmd.OpenForm "FormB",,,,,, Me.tbID & ", " & Me.tbFullName & ", " & NZ(Me.tbAddress,"")
    (I used "FullName because "Name" is a reserved word in Access.) If a control value is or could be NULL, you would need to use the NZ() function to avoid passing a null value.

    In the form open event of "FormB", you use the split command to separate the values. Since the values would be in an array, loop thru the array, assigning the values to the proper controls.

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

Similar Threads

  1. VBA Pass-through Query with Variable
    By smaumau in forum Programming
    Replies: 0
    Last Post: 12-06-2010, 09:10 AM
  2. Replies: 3
    Last Post: 11-26-2010, 12:38 PM
  3. Refering to variable form names inside a variable
    By redpetfran in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 01:39 PM
  4. Replies: 5
    Last Post: 04-05-2010, 11:43 AM
  5. pass a variable to the MsgBox function
    By 3dmgirl in forum Programming
    Replies: 2
    Last Post: 04-19-2007, 07:14 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