SQL error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CLSkcab
    New Member
    • Aug 2014
    • 26

    #1

    SQL error

    Background: Front End MS Access 2010 with VBA; Backend SQL Server 2008; Still learning SQL

    I have the following statement coded
    Code:
    gblsSQL = "Select Role FROM [dbo_UserProgram] Where Program='Security' IDUser=" & gblID & ";"
    It is generating this error: Run-time error (missing operator) in query expression Program='Securi ty' IDUser=1'. What is wrong?
    Thanks in advanced.
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    You are missing the comma between your two criteria. You should have
    Code:
    gblsSQL = "Select Role FROM [dbo_UserProgram] Where Program='Security' AND IDUser=" & gblID & ";"

    Comment

    • zmbd
      Recognized Expert Moderator Expert
      • Mar 2012
      • 5501

      #3
      Please place a "stop" either before or after the string.
      execute to the stop.
      Then <ctrl><g>
      Then in the immediate window type
      Code:
      ?gblsSQL
      [enter]
      (also appears to be missing comma)
      Cut and paste back the resolved string.

      Comment

      • CLSkcab
        New Member
        • Aug 2014
        • 26

        #4
        I did as you requested and put in (,). This time I get the following message: Run-time error 3075, Syntax error (comma) in query expression 'Program='Secur ity', IDUser=1'

        Comment

        • zmbd
          Recognized Expert Moderator Expert
          • Mar 2012
          • 5501

          #5
          Please do the troubleshooting step as outlined in my post.

          Comment

          • Seth Schrock
            Recognized Expert Specialist
            • Dec 2010
            • 2965

            #6
            Oh, duh. The WHERE clause needs the word And or Or for multiple criteria. See my fix in post #2. And please do post the information requested by zmbd.

            Comment

            • CLSkcab
              New Member
              • Aug 2014
              • 26

              #7
              I have a SQL table record:

              ID int primary key
              IDUser int secondary key points to the parent
              Program varchar(50)
              Role varchar(5)
              .
              .
              .

              I know the secondary key and program values. Hoe can I get the Role value? Any help will be appreciated. I did find where you can't use a Select like this.

              Comment

              • zmbd
                Recognized Expert Moderator Expert
                • Mar 2012
                • 5501

                #8
                CLSkcab,

                What we need to see here is the code that you are using and the resolved string as requested.

                You can indeed retrieve the information you are looking for using a select query as the recordset-object. You only need to provide a clear question and enough detail for us to proceed.
                (^_^)

                Comment

                • Luuk
                  Recognized Expert Top Contributor
                  • Mar 2012
                  • 1043

                  #9
                  see first reply of 'Seth Schrock' where he said this (i only quote the SQL):
                  Code:
                  Select Role 
                  FROM [dbo_UserProgram] 
                  Where Program='Security' 
                    [B]AND[/B] IDUser=" & gblID & ";"

                  Comment

                  Working...