I have a button on the main form, Form1, that opens another form, Form2, to the same record as the first form.
This code works fine when using the main table. The primary key is ID. I want to sort the data in the main table by Field1 using a query, Query1, and open Form2. I tried to change the the code as shown below, but in this case Form2 opens at the first record in the query, not to the record in Form1. For example if Form1 is at record 100, Form2 will show record 1.
Maybe someone knows how to make it work. Thanks.
Private Sub btnOpenMulti_Click()
DoCmd.OpenForm "Form2", OpenArgs:=" WHERE ID >= " & [ID]
' Changed to: DoCmd.OpenForm "Form2", OpenArgs:="[Field1]"
End Sub
Form2
Private Sub Form_Load()
' Open the recordset and update the controls
CurrentPage = 1
Set cn = CurrentProject.Connection
Set rst = New ADODB.Recordset
With rst
.PageSize = 8
.ActiveConnection = cn
.Source = "SELECT * FROM Form1" & Me.OpenArgs
' Changed to: .Source = "Query1 '" & Me.OpenArgs & "'"
.LockType = adLockOptimistic
.CursorType = adOpenStatic
.Open
End With
UpdateControls
End Sub
This code works fine when using the main table. The primary key is ID. I want to sort the data in the main table by Field1 using a query, Query1, and open Form2. I tried to change the the code as shown below, but in this case Form2 opens at the first record in the query, not to the record in Form1. For example if Form1 is at record 100, Form2 will show record 1.
Maybe someone knows how to make it work. Thanks.
Private Sub btnOpenMulti_Click()
DoCmd.OpenForm "Form2", OpenArgs:=" WHERE ID >= " & [ID]
' Changed to: DoCmd.OpenForm "Form2", OpenArgs:="[Field1]"
End Sub
Form2
Private Sub Form_Load()
' Open the recordset and update the controls
CurrentPage = 1
Set cn = CurrentProject.Connection
Set rst = New ADODB.Recordset
With rst
.PageSize = 8
.ActiveConnection = cn
.Source = "SELECT * FROM Form1" & Me.OpenArgs
' Changed to: .Source = "Query1 '" & Me.OpenArgs & "'"
.LockType = adLockOptimistic
.CursorType = adOpenStatic
.Open
End With
UpdateControls
End Sub