Run-time error 3075 syntax error (missing operator) in query expression

Greeting All,

I have the following code to check if the instracutor had the same course before or not:

Dim strCriteria As String
    If Not IsNull(Me.cboprogram_name) Then

        strCriteria = _
          "Instructor_id = " & Me.txtInstructor_id & _
         " And program_name = " & Me.cboprogram_name & _
         " And CourseID <> " & Me.txtCourseID

    If DCount("*", "InstructorCoursetbl", strCriteria) > 0 Then
        MsgBox " Course Already Registered for this Instructor", vbExclamation, "Invalid Operation"
    End If
    End If

Above code is located on the event of cboprogram_name beforeupdate event but I got the following error msg:

Run-time error 3075 syntax error (missing operator) in query expression 'Instructor_ID= And Program_name=2 And CourseID<>58'

Any help please?


Question Info

Last updated February 6, 2018 Views 1,758 Applies to:

Assumptions:  Instructor_ID and CourseID are number fields.

ProgramName is a Text field.  If so, you must delimit Me.cboProgram_Name with quote marks when you build strCriteria.  If program Name is a number field then drop the added Chr(34) in the following.


I think you need to check and see if all the relevant controls have a value.

IF Len(Me.cboProgram_Name & "") >0 _

   AND Len(Me.txtInstructorID & "") > 0 _

   AND Len(Me.txtCourseID & "") > 0 THEN

  strCriteria = _
          "Instructor_id = " & Me.txtInstructor_id & _
         " And program_name = " & Chr(34) & Me.cboprogram_name & Chr(34)  _
         " And CourseID <> " & Me.txtCourseID



Also why are you checking that courseID is not equal to txtCourseID?  I would think you would be checking for a match on courseID. On the other hand you know your data better than I do.

John P Spencer
Access MVP 2002-2005, 2007-2011

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.