Syntax Error missing operator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nerd4access
    New Member
    • Jan 2008
    • 22

    #1

    Syntax Error missing operator

    Hello all! I am not new to access, but new to coding (and posting). I have a database that I have created and need some help with a login form. When a user opens the database, a form pops up asking for a username and password. They can choose their name from a combobox and enter apassword into a textbox.

    If the default password is entered, another forms pops up asking the user to change their password (this is where my problem comes in):

    The first textbox on the Change Password form asks the user to enter a new password and the second textbox asks the user to enter the password in again to confirm it. If the information entered in both textboxes are equal, I would like to use a RunSql to update the table that holds the password information The code I am using is as follows:

    Code:
    Private Sub cmdSubmit_Click()
    Dim strSQL As String
     
     If txtNewPswd <> txtConfirmPswd Then
        MsgBox "Passwords don't match. Please try again.", vbOKOnly
       Else
     If txtNewPswd = txtConfirmPswd Then
        strSQL = " UPDATE tblUserDefinitions"
        strSQL = strSQL & " SET Password = ' " & Me.txtConfirmPswd
        strSQL = strSQL & " 'WHERE lngEmpID = '" & Me.txtlngEmpID & "';"
    
        DoCmd.RunSQL strSQL
        MsgBox "Password change successful!", vbOKOnly
    
        DoCmd.OpenForm "frmLogon"
        DoCmd.Close acForm, "frmPWChng", acSaveNo
        End If
    End If
    End Sub
    I am getting a run-time error stating that there is a syntax error (missing operator) in query expression. I am using Access 2007. Please help!
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    Add a space after the ' and before the WHERE like:
    Code:
    strSQL = strSQL & " ' WHERE lngEmpID = '" & Me.txtlngEmpID & "';"
    Nic;o)

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      Also remove spaces from lines #9 (after the ') & #10 (before the '). Otherwise the password will be stored with spaces surrounding it and will never be matched.

      Comment

      • nerd4access
        New Member
        • Jan 2008
        • 22

        #4
        That worked. Thank you for help. Much appreciated!

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          Thank you for making the question clear & simple to answer.

          Welcome to TheScripts :)

          Comment

          Working...