syntax error (missing operator) in query expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Tyler

    #1

    syntax error (missing operator) in query expression

    I am having a hard time trying to code around this. I have a checkbox
    field in a MSAccess table called "100Fund" which is identical in
    structure to other checkbox fields in the same table. I have a combo
    box listing the various fields in the table for the user to select as a
    table filter. If I use the following code in VB6 - where the user
    selects the field "100Fund" - I get the above error:

    Dim varchoice As String
    varchoice = cmbFilter.Text
    Adodc1.RecordSo urce = "select * from [A Table] where " & varchoice & "
    = True order by LastName"
    Adodc1.Refresh

    All other checkbox fields work fine when selected. I appreciate that
    it has to do with the field name starting with "100" but varchoice is
    clearly a string variable. Using Cstr() doesn't help.

    Any ideas? Thanks in advance!

    Peter Tyler

  • Lyle Fairfield

    #2
    Re: syntax error (missing operator) in query expression

    You might try:
    where [" & varchoice & "]

    Comment

    • Peter Tyler

      #3
      Re: syntax error (missing operator) in query expression

      It works well. Thanks Lyle!

      But why? I would normally only use square brackets where the field (or
      table) name has a space.

      Peter

      Comment

      • Lyle Fairfield

        #4
        Re: syntax error (missing operator) in query expression

        from help:

        The setting or return value is a String that specifies a name. The name
        must start with a letter. The maximum number of characters depends on
        the type of object Name applies to, as shown in Remarks. It can include
        numbers and underscore characters ( _ ) but can't include punctuation
        or spaces.

        Comment

        • Peter Tyler

          #5
          Re: syntax error (missing operator) in query expression

          OK thanks.

          Peter

          Comment

          Working...