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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Carrying Form Variables to Another Form

Status
Not open for further replies.

DoDo1975

Technical User
Jun 4, 2002
18
CA
Hi,

I have a form that I use to open another form to gather data. In the second form opened, users are to pick certain fields that they want used in a query. On close of this form, I would like to pass the chosen information to the original form, into a listbox or textbox. Can anyone tell me how to do this?

The original form brings up the 2nd form using the docmd.openform method. I want the code on the original form to then wait for the data to be entered onto the 2nd form before continuing, and when the user presses a button on the second form, the data is "sent" to the original form and the code continues to operate.

Any help is appreciated. Thanks in advance.

Joel Lindsay
Vancouver Canada
 
Easiest way is to create some Public variables to hold the values. Open up the second form, wait until it closes and set the variables before you close. Then pick them up again in your first form.

e.g.
In a module ...
Public QueryField1 As String

Public Function FormOpen(FormName As String) As Boolean
On Error Resume Next
Dim S As String
S = Forms(FormName).Name
If Err.Number <> 0 Then
Err.Clear
FormOpen = False
Else
FormOpen = True
EndIf
End Function

In the first form ...
DoCmd.OpenForm &quot;frmFirst&quot;
DoEvents
While FormOpen(&quot;frmFirst&quot;)
DoEvents
Wend
X = QueryField1
 
open the form in the dialog mode:

DoCmd.OpenForm &quot;YourForm&quot; , , , , , acDialog

This will pause the code until you close the form.

On the Close event of the second form, update the first form with the data you entered.

Forms![FirstForm]![FieldName1] = Me![FieldName1]
Forms![FirstForm]![FieldName2] = Me![FieldName2]

Good luck! Anthony J. DeSalvo
President - ScottTech Software
&quot;Integrating Technology with Business&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top