By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,086 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,086 IT Pros & Developers. It's quick & easy.

Syntax Error missing operator

P: 22
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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSubmit_Click()
  2. Dim strSQL As String
  4.  If txtNewPswd <> txtConfirmPswd Then
  5.     MsgBox "Passwords don't match. Please try again.", vbOKOnly
  6.    Else
  7.  If txtNewPswd = txtConfirmPswd Then
  8.     strSQL = " UPDATE tblUserDefinitions"
  9.     strSQL = strSQL & " SET Password = ' " & Me.txtConfirmPswd
  10.     strSQL = strSQL & " 'WHERE lngEmpID = '" & Me.txtlngEmpID & "';"
  12.     DoCmd.RunSQL strSQL
  13.     MsgBox "Password change successful!", vbOKOnly
  15.     DoCmd.OpenForm "frmLogon"
  16.     DoCmd.Close acForm, "frmPWChng", acSaveNo
  17.     End If
  18. End If
  19. 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!
Mar 7 '08 #1
Share this Question
Share on Google+
4 Replies

Expert 2.5K+
P: 3,072
Add a space after the ' and before the WHERE like:
Expand|Select|Wrap|Line Numbers
  1. strSQL = strSQL & " ' WHERE lngEmpID = '" & Me.txtlngEmpID & "';"
Mar 7 '08 #2

Expert Mod 15k+
P: 31,473
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.
Mar 7 '08 #3

P: 22
That worked. Thank you for help. Much appreciated!
Mar 11 '08 #4

Expert Mod 15k+
P: 31,473
Thank you for making the question clear & simple to answer.

Welcome to TheScripts :)
Mar 11 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.