I am an Access 97 developer and I am trying to open a form and find a record based on the value of another form.
I have tried using the same syntax listed below but it does not like the nomatch property.
Does anyone have the code which opens one form from another and goes to a specific record?
' Declare Variables
Dim FormName As String
Dim RecordNumber As Variant
Dim frm As Form
Dim rst As Recordset
Dim strCriteria As String
' Store the personid field to the variable record number
RecordNumber = Me![personid]
' Store the name of the form you want to open
FormName = "F_Person"
' Open the form
DoCmd.OpenForm FormName
' Create a recordset based on the form just opened and find the first matching record
Set frm = Forms(FormName)
strCriteria = "[PersonId] Like '*" & RecordNumber & "*'"
Set rst = frm.RecordsetClone
rst.FindFirst strCriteria
' if there is no matching records then put up a message otherwise go to the selected record.
If rst.NoMatch Then
MsgBox "Coundn't find record"
Else
frm.Bookmark = rst.Bookmark
End If
I have tried using the same syntax listed below but it does not like the nomatch property.
Does anyone have the code which opens one form from another and goes to a specific record?
' Declare Variables
Dim FormName As String
Dim RecordNumber As Variant
Dim frm As Form
Dim rst As Recordset
Dim strCriteria As String
' Store the personid field to the variable record number
RecordNumber = Me![personid]
' Store the name of the form you want to open
FormName = "F_Person"
' Open the form
DoCmd.OpenForm FormName
' Create a recordset based on the form just opened and find the first matching record
Set frm = Forms(FormName)
strCriteria = "[PersonId] Like '*" & RecordNumber & "*'"
Set rst = frm.RecordsetClone
rst.FindFirst strCriteria
' if there is no matching records then put up a message otherwise go to the selected record.
If rst.NoMatch Then
MsgBox "Coundn't find record"
Else
frm.Bookmark = rst.Bookmark
End If