Solved Run-time error '3077' Syntax error (missing operator) in expression. (1 Viewer)

5hadow

Member
Local time
Today, 18:51
Joined
Apr 26, 2021
Messages
89
I have Run-time error '3077' Syntax error (missing operator) in expression error come up when trying to .findFirst in my recordset.

Code:
 'Criteria'
 strCrit = "pkEventID = " & DMax("pkEventID", "tblEvents", "[fkAircraftID] = " & Me.cboTail & " AND [fldDateEnd] is null")

'Part of code'
                .FindFirst strCrit
                If .NoMatch Then
                    Resume Next
                End If

It works ok when there are matching records. However, when it's a new record I get the error. I expect it not to find a record, but I don't want the error.

Does anyone know what's wrong with syntax? I also tried this:
strCrit = "pkEventID = " & DMax("pkEventID", "tblEvents", "[fkAircraftID] = " & Me.cboTail & " AND [fldDateEnd] is null") & ""
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:51
Joined
May 7, 2009
Messages
19,229
maybe put Nz():

strCrit = "pkEventID = " & Nz(DMax("pkEventID", "tblEvents", "[fkAircraftID] = " & Nz(Me.cboTail, 0) & " AND [fldDateEnd] is null"), 0) & ""
 

moke123

AWF VIP
Local time
Today, 18:51
Joined
Jan 11, 2013
Messages
3,912
Add a debug.print strcrit to see what it resolves to.

is [fkAircraftID] numeric?
 

5hadow

Member
Local time
Today, 18:51
Joined
Apr 26, 2021
Messages
89
maybe put Nz():

strCrit = "pkEventID = " & Nz(DMax("pkEventID", "tblEvents", "[fkAircraftID] = " & Nz(Me.cboTail, 0) & " AND [fldDateEnd] is null"), 0) & ""
That works, thanks!
 

Users who are viewing this thread

Top Bottom