Matthew said:
I have a form containing some fields of data that correspond to other fields
of data on another form. There is a button on form1 that opens a new record
on form2. I want to take some of the data fields on form1 and populate the
corresponding fields on form2 with the values. What is the best way to do
this?
Thanks
Matt
Lookup OpenArgs property in help.
The following example uses the OpenArgs property to open the Employees
form to a specific employee
record and demonstrates how the OpenForm method sets the OpenArgs
property. You can run this
procedure as appropriate — for example, when the AfterUpdate event
occurs for a custom dialog
box used to enter new information about an employee.
Sub OpenToCallahan()
DoCmd.OpenForm "Employees", acNormal, , , acReadOnly, , "Callahan"
End Sub
Sub Form_Open(Cancel As Integer)
Dim strEmployeeName As String
' If OpenArgs property contains employee name, find corresponding
' employee record and display it on form. For example,
' if the OpenArgs property contains "Callahan", move to first
' "Callahan" record.
strEmployeeName = Forms!Employees.OpenArgs
If Len(strEmployeeName) > 0 Then
DoCmd.GoToControl "LastName"
DoCmd.FindRecord strEmployeeName, , True, , True, , True
End If
End Sub
The next example uses the FindFirst method to locate the employee named
in the OpenArgs property.
Private Sub Form_Open(Cancel As Integer)
If Not IsNull(Me.OpenArgs) Then
Dim strEmployeeName As String
strEmployeeName = Me.OpenArgs
Dim RS As Recordset
Set RS = Me.RecordsetClone
RS.FindFirst "LastName = '" & strEmployeeName & "'"
If Not RS.NoMatch Then
Me.Bookmark = RS.Bookmark
End If
End If
End Sub
Ron