Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving data from one form and using in another form

Status
Not open for further replies.

pparadis

MIS
Dec 5, 2000
22
US
Is there a way to take data from one form, say ProjectID, and save it so it can be used in another form (i.e. to use in a querey to get information about that project). Currently I am writing data to a table I made to hold that information and then retrieving it from that table when I open the next form. I am concerned that will cause problems when there are multiple users. Is there some type of variable that can be used between forms? Thanks in advance.
 
Hi!

If you are opening the second form from the first, using a DoCmd.OpenForm method, you can use the OpenArgs to pass the information.

Dim strOpenArgs as String

strOpenArgs = FirstTextBox & ";" & SecondTextBox & ";" & ThirdTextBox & etc.

Then, in the Form_Load procedure of the second form use:

Dim intSemiColon As Long
Dim strOpenArgs as String
Dim strTextBoxName As String
Dim intTextBoxInd As Integer

strOpenArgs = Me.OpenArgs
intSemiColon = InStr(strOpenArgs, ";")
intTextBoxInd = 1
Do While intSemiColon <> 0
strTextBoxName = &quot;Text&quot; & Format(intTextBoxInd)
Me!Controls(strTextBoxName).Value = Left(strOpenArgs, intSemiColon - 1)
strOpenArgs = Mid(strOpenArgs, intSemiColon + 1)
intSemiColon = InStr(strOpenArgs, &quot;;&quot;)
intTextBoxInd = intTextBoxInd + 1
Loop
strTextBoxName = &quot;Text&quot; & Format (intTextBoxInd)
Me!Controls(strTextBoxName).Value = strOpenArgs

hth
Jeff Bridgham
 
You can also store the value in a global variable in your main module.

Module1:
Public ProjectID As Long

Form1:
ProjectID = CLng(Text1.Text)

Form2:
Text1.Text = Project ID
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top