Variable Referencing

rdg0351

Registered User.
Local time
Today, 01:40
Joined
Nov 29, 2010
Messages
19
I'm relatively new to Access, but am a long-time programmer. I'm confused on variable scoping. I have "form1" that has a button which initiates a pop-up "form2". The data contained in "form2" is a child of "form1". I am using a pop-up scenario since I already am displaying another child on "form1". My question is: How do I reference the data from "form1" prior to posting a record to the "form2" table while on "form2"? I thought the recordset would be "current" from "form1" while on "form2"; or, I'm just losing my mind?
 
That certainly helps me, but what if I don't want to display a list, but rather display a form and capture data to post? Sort of like an audit trail capability?
 
I would advise you simply use an unbound form (i.e. form2), open form2 and set the values of the controls from form1 like so:
Code:
Docmd.OpenForm "Form2"
With Forms("Form2")
     .txtbox1.Value = Me![Field1]
     .txtbox2.Value = Me![Field2]
.... so on and so forth.
End With
If you want to save back the values from form2 to form1, then on the UNLOAD event of form2 do the reverse, like this:
Code:
With Forms!Form1
      ![Field1] = Me.txtbox1.Value
      ![Field2] = Me.txtbox2.Value
 .... so on and so forth.
 End With

Edit: I made some changes to the second block of code.
 
Last edited:
VBAInet, Thanks for everything. The use of WITH certainly got me over my hurdle. Can you recommend any reference material that discusses logic flow and data referencing techniques between forms? Certainly the "scope" and "focus" of the variables are what is giving me fits.
 

Users who are viewing this thread

Back
Top Bottom