Does anyone know what the missing operator is?
Thanks
DS
Private Sub Form_Open(Cancel As Integer)
Forms!MenuItems.RecordsetClone.FindFirst "[MenuCatID] = " &
Forms!MenuItems![Text49] & ""
Forms!MenuItems.Bookmark = Forms!MenuItems.RecordsetClone.Bookmark
End Sub
I can't quite imagine why opening this form (which presumably is not
'MenuItems') causes the MenuItems form to move to a particular record,
the ID of which was already showing on the form itself - but I assume you
know what you are doing there.
Perhaps you should make sure you have a valid MenuCatID before you
proceed with your code. In the example I give I check to see the form is
open, then try to get a non-zero long integer before I do a FindFirst. I
also check the .NoMatch criteria before I sync the bookmark of the
recordset with the recordsetclone object. I also set cancel to true so
that this form will not open unless it finds the matching record. I also
include some more generalised error-handling for unexpected errors.
I can't swear it will do what you need since I don't have all the details
(eg should MenuCatID be a non-zero long integer?) - but it might point
you in the right direction:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Handler
Dim lngID As Long
Cancel = True
If IsFormLoaded("MenuItems") Then
lngID = CLng(Nz(Forms!MenuItems!Text49, 0))
End If
If lngID < 1 Then
MsgBox "Missing ID from form 'MenuItems'", vbExclamation
Exit Sub
End If
With Forms!MenuItems.RecordsetClone
.FindFirst "MenuCatID=" & CStr(lngID)
If Not .NoMatch Then
Forms!MenuItems.Bookmark = .Bookmark
Cancel = False
Else
MsgBox "Cannot locate record", vbExclamation
End If
End With
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub
Private Function IsFormLoaded(strName As String)
IsFormLoaded = (SysCmd(acSysCmdGetObjectState, acForm, strName) <> 0)
End Function