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

Passing Data Between Forms

Status
Not open for further replies.

Hammondo

MIS
Jan 14, 2002
23
NL
I have two forms. Form1 and Form2.

-On Form1 TextBox1 (an unbound text box) contains a value. On Form1 also is a button, which when pressed opens Form2

-Form2 on opening creates a new record in TableA. TableA has FieldA which I'd like to populate with the value contained in TextBox1 on FormA. I'd like this to happen automatically.

How can a pass the value contained in Form1, TextBoxA, to Form2, TableA, FieldA automatically when Form2 is opened?

Help!

 
You could just bind a textbox on form 2 to form 1, by putting something like this in the control source:

=[forms]![form1]![nameofform1textbox]

It won't be editable on form2 if you do this; for display only.

Or, you could pass a value to form 2 when it's opened by including it as the 'openargs' paramater of the docmd.open form action. That would require additional programming to take the paramater and put it in the textbox. -- Herb
 
Or you could build public properties into the forms and access them from the other form. I prefer this method because you can write code to verify and return whatever you want. For instance, on one form you could enter:

Public Property Get AnyPropertyName() As Variant

If Len(Me.txtAnyTextBox)>0 Then
AnyPropertyName = Me.txtAnyTextBox
Else
AnyPropertyName = "None"
End If

End Property

Then, on the other form you write code to access the property.

Dim frm As Form
If IsLoaded("frmAnyFormName") Then
Set frm = Forms("frmAnyFormName")
Else
MsgBox "This form is not loaded"
End If

If Not frm Is Nothing Then
varValueFromOtherForm = frm.AnyPropertyName
End If

Just remember that the form is nothing but a Class module and you are building public interfaces to get information from the class. So if you create a form object you can get properties, as in the case of the AnyPropertyName or cause actions by creating a public method (function or subroutine).

Steve King Growth follows a healthy professional curiosity
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top