Syntax error(missing operator) in query expression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lieven
    New Member
    • Mar 2010
    • 2

    Syntax error(missing operator) in query expression

    The problem is fairly complex. I have a table where I can add records. These records have several parts. Each record consists of ID, Date, Train Number and many more. I have a form where I can add records. This form has two pages. One for adding records ( this part works fine ) and then I have another form where I can search records by filtering. The filtering happens by using an options group with different options button. I added a button to this page to display the filtered records on another form. When I filter by ID everything works, when I filter by Date it works too so I thought the other options would work fine too, but if I filter by Train number it doesn't work. This is the fault message I get: Syntax error( misssing operator ) in query expression
    'Train Number = Forms![Faults_Form]![Firsttrainnumbe r]' I have no idea why it doesn't work. Lets finish by adding some code. The date part works but the train number part doesn't.

    Private Sub Search_Workorde r_Button_Click( )
    On Error GoTo Err_Search_Work order_Button_Cl ick


    Dim Filtervoorwaard e



    Select Case Me![Filter_options_ Frame]
    Case 1

    DoCmd.OpenForm "Faults_Overvie w_Form"


    Case 2

    ' Als besturingseleme nt blanco is, bericht weergeven.
    If IsNull(Forms![Faults_Form]![Date1]) Then
    strBer = "Insert a date in the textbox."
    intStijl = vbOKOnly
    strTitel = "Date selection"
    MsgBox strBer, intStijl, strTitel
    Forms![Faults_Form]![Date1].SetFocus
    Else
    Filtervoorwaard e = "Date = Forms![Faults_Form]![Date1]"
    DoCmd.OpenForm "Faults_Overvie w_Form", , , Filtervoorwaard e


    End If
    Case 3

    If IsNull(Forms![Faults_Form]![Firsttrainnumbe r]) Then
    strBer = "Insert a train number (101-120) in the textbox."
    intStijl = vbOKOnly
    strTitel = "Train selection"
    MsgBox strBer, intStijl, strTitel
    Forms![Faults_Form]![Firsttrainnumbe r].SetFocus
    Else
    Filtervoorwaard e = "Train Number = Forms![Faults_Form]![Firsttrainnumbe r]"
    DoCmd.OpenForm "Faults_Overvie w_Form", , , Filtervoorwaard e


    End If

    case 1 and 2 are working but case 3 is not.

    Thanks
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi

    Just one possible suggestion, you could try this:

    Filtervoorwaard e = "[Train Number] = Forms![Faults_Form]![Firsttrainnumbe r]"

    It's not a good idea to have spaces in fierld names!


    MTB

    Comment

    • Lieven
      New Member
      • Mar 2010
      • 2

      #3
      Thanks Mike,

      good tip!! I changed it and it seems to work now.

      Comment

      Working...