T
Tom Lewis
I am using an OpenArgs property to pass a primary key
value to a form, and want to open the form with this
record active. When I try to do this, the form opens, but
the bookmark to the specified record is ignored. Oddly, if
I change the form to design view and then back again to
form view, the desired record is current when the form
opens.
The code I am using is:
Private Sub Form_Open(Cancel As Integer)
If Not IsNull(Me.OpenArgs) Then
Dim rst As ADODB.Recordset
Dim strSearchExp As String
Dim varBookMark As Variant
Set rst = Me.RecordsetClone
strSearchExp = "[FacilityID] = " & Me.OpenArgs
With rst
.MoveFirst
.Find strSearchExp
If Not .EOF Then
varBookMark = rst.Bookmark
Me.Bookmark = varBookMark
End If
End With
rst.Close
Set rst = Nothing
End If
End Sub
I have been able to confirm that the OpenArgs property is
being received by the form, but assigning the bookmark is
not working. I have also tried to use the DoCmd.GoToRecord
method to open the form at the desired record, but this
seems to result in the same problem. I am new to ADO, so I
suspect I am missing something simple, but I have not been
able to figure out where the problem is.
Any help will be greatly appreciated.
Tom
value to a form, and want to open the form with this
record active. When I try to do this, the form opens, but
the bookmark to the specified record is ignored. Oddly, if
I change the form to design view and then back again to
form view, the desired record is current when the form
opens.
The code I am using is:
Private Sub Form_Open(Cancel As Integer)
If Not IsNull(Me.OpenArgs) Then
Dim rst As ADODB.Recordset
Dim strSearchExp As String
Dim varBookMark As Variant
Set rst = Me.RecordsetClone
strSearchExp = "[FacilityID] = " & Me.OpenArgs
With rst
.MoveFirst
.Find strSearchExp
If Not .EOF Then
varBookMark = rst.Bookmark
Me.Bookmark = varBookMark
End If
End With
rst.Close
Set rst = Nothing
End If
End Sub
I have been able to confirm that the OpenArgs property is
being received by the form, but assigning the bookmark is
not working. I have also tried to use the DoCmd.GoToRecord
method to open the form at the desired record, but this
seems to result in the same problem. I am new to ADO, so I
suspect I am missing something simple, but I have not been
able to figure out where the problem is.
Any help will be greatly appreciated.
Tom