Missing Operator

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

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
 
DS said:
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
 
Justin said:
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
The code works fine when I run it from a button.

Me.RecordsetClone.FindFirst "[MenuCatID] = " & Me![Text49] & ""
Me.Bookmark = Me..RecordsetClone.Bookmark

but not on the onopen of a form. Is this on the wrong place?

I'm opening a second form based on 2 criteria This only shows one
record. I need to have them all.

If I remove the second criteria I get all of the records I need but it
goes to the first record not the selected record.

Is this clearer?
Thnaks
DS
 
DS said:
Justin said:
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
The code works fine when I run it from a button.

Me.RecordsetClone.FindFirst "[MenuCatID] = " & Me![Text49] & ""
Me.Bookmark = Me..RecordsetClone.Bookmark

but not on the onopen of a form. Is this on the wrong place?

I'm opening a second form based on 2 criteria This only shows one record.
I need to have them all.

If I remove the second criteria I get all of the records I need but it
goes to the first record not the selected record.

Is this clearer?
Thnaks
DS



If you write more lines of code, taking it step by step, your problem may
become apparent. Get the value of Me![Text49] and explicitly convert it
into a long integer, before you move on. Either use a breakpoint and step
through it or put a messagebox on the screen to show you what this value is.
My guess is that, if there is a difference in behaviour when calling from
the Open event and a button's Click event, then [Text49] is not yet loaded
with the right value during the Open event. Once the form has opened,
loaded and you click the button, the expected value is there.
 
Justin said:
Justin said:
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

The code works fine when I run it from a button.

Me.RecordsetClone.FindFirst "[MenuCatID] = " & Me![Text49] & ""
Me.Bookmark = Me..RecordsetClone.Bookmark

but not on the onopen of a form. Is this on the wrong place?

I'm opening a second form based on 2 criteria This only shows one record.
I need to have them all.

If I remove the second criteria I get all of the records I need but it
goes to the first record not the selected record.

Is this clearer?
Thnaks
DS




If you write more lines of code, taking it step by step, your problem may
become apparent. Get the value of Me![Text49] and explicitly convert it
into a long integer, before you move on. Either use a breakpoint and step
through it or put a messagebox on the screen to show you what this value is.
My guess is that, if there is a difference in behaviour when calling from
the Open event and a button's Click event, then [Text49] is not yet loaded
with the right value during the Open event. Once the form has opened,
loaded and you click the button, the expected value is there.
thanks I'll give it a try
ds
 
Justin said:
Justin said:
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

The code works fine when I run it from a button.

Me.RecordsetClone.FindFirst "[MenuCatID] = " & Me![Text49] & ""
Me.Bookmark = Me..RecordsetClone.Bookmark

but not on the onopen of a form. Is this on the wrong place?

I'm opening a second form based on 2 criteria This only shows one record.
I need to have them all.

If I remove the second criteria I get all of the records I need but it
goes to the first record not the selected record.

Is this clearer?
Thnaks
DS




If you write more lines of code, taking it step by step, your problem may
become apparent. Get the value of Me![Text49] and explicitly convert it
into a long integer, before you move on. Either use a breakpoint and step
through it or put a messagebox on the screen to show you what this value is.
My guess is that, if there is a difference in behaviour when calling from
the Open event and a button's Click event, then [Text49] is not yet loaded
with the right value during the Open event. Once the form has opened,
loaded and you click the button, the expected value is there.
Patience is a virtue! I put the code on the first form and that worked
fine. Thanks
DS
 
Back
Top