I have been using the following code from Paul Baldy to open a form at the record selected from the first form.
Code:
Dim rs As Object
Dim lngBookmark As Long
'set a variable to the current record
lngBookmark = Me.txtEmpID
'open the new form
DoCmd.OpenForm "frmEmployeesDetail"
'take it to the selected record
Set rs = Forms!frmEmployeesDetail.RecordsetClone
rs.FindFirst "EmpID = " & lngBookmark
Forms!frmEmployeesDetail.Bookmark = rs.Bookmark
Set rs = Nothing
This works well when the variable is a number. I need to tweak the code to open another form based on a text variable. I thought all I needed to do was change
Dim lngBookmark As Long to: Dim lngBookmark as String
Here is my code:
Code:
Dim rs As Object
Dim lngBookmark As String
'set a variable to the current record
lngBookmark = Me.ItemCode
'open the new form
DoCmd.OpenForm "frmQuestionSummary"
DoCmd.Close acForm, "frmQuestionSummaryCOUNSEL"
'take it to the selected record
Set rs = Forms!frmQuestionSummary.RecordsetClone
rs.FindFirst "ItemCode = " & lngBookmark
Forms!frmQuestionSummary.Bookmark = rs.Bookmark
Set rs = Nothing
I am getting an error message saying that Jet engine does not recognize my variable as a valid field name or expression. Can anybody see where I have made a mistake in my code? Thanks