Run Time Error 3075 Missing Operator

AndyCabbages

Registered User.
Local time
Yesterday, 23:54
Joined
Feb 15, 2010
Messages
74
Basically I have a form where you select 3 types of quipment to add to a table, but when you try and add the equipment you get the following error:
Run Time Error 3075 Missing Operator

I have looked this up and from what I can gather its a syntax error somewhere, but my coding is not great so I cant figure out where the problem is. The code where for the function with the error is:

Private Function workingDates()

Dim dbsThisDatabase As Database
Set dbsThisDatabase = CurrentDb()
Dim workingRecords As DAO.Recordset
recordNo = Forms![Hire Contracts]!Record_Number
datesSQL = "SELECT * FROM Hired where Record_number = " & recordNo & " and defaultDates = True"
Set workingRecords = dbsThisDatabase.OpenRecordset(datesSQL)
If workingRecords.RecordCount = 0 Then
Forms![Hire Contracts]!hireFrom = Null
Forms![Hire Contracts]!hireTo = Null
Forms![Hire Contracts]!noOfDays = Null
Else
Forms![Hire Contracts]!hireFrom = workingRecords!Hired_From
Forms![Hire Contracts]!hireTo = workingRecords!Hired_To
Forms![Hire Contracts]!noOfDays = workingRecords!WorkingDays
End If
End Function

The part in red is the line that the debugger points you to.
 
What is the data type of Record_number in the table?
 
It is the primary key of the table 'Order' and is of type Autonumber (Long Integer)
 
And defaultDates is Yes/No? Add this line after the SQL is created:

Debug.Print datesSQL

which will print out the finished SQL to the VBA Immediate window. You can examine it there and see if you spot the problem. If not, copy the SQL into an new query (in SQL view) and try to run it. You should get a more descriptive error.
 
I get the following:

Syntax error (missing operator) in query expression 'Record_number = and defaultdates = true'

It seems highlights the 'and' part of the code
 
From that error, there's no value for recordNo. Double check that there is a value in that control, and the spelling is correct and such.
 

Users who are viewing this thread

Back
Top Bottom