Error in Update Statement

sandy1234

New member
Local time
Today, 19:25
Joined
Jun 22, 2009
Messages
2
Dear All,

I am getting "Syntex Error in Update Statement" in below code.

Please help mt to solve this.

Private Sub btn_submit_Click()
txt_pwd.SetFocus
If Trim(Len(txt_pwd.Text)) = 0 Then
MsgBox "Please Enter New Password"
txt_pwd.SetFocus
Exit Sub
End If
'Update New Password
sql = "Update USERLIST set password='" & txt_pwd.Text & "' where userid='" & userid & "'"
cn.Execute (sql)
If Err.Number > 0 Then
MsgBox Err.Description
Else
MsgBox "Password has been changed successfully.Please login Again", vbOKOnly
End
End If
 
Might try:
Code:
sql = "Update USERLIST set USERLIST.[password] ='" & Me.txt_pwd & "' where USERLIST.[userid] ='" & Me.userid & "'"
 
Thanks, It is working now
 
1. Don't use the .TEXT part as the control needs the focus when you do this. If you use the .Value (and the default is .Value so you don't have to include it) you don't need the focus on the control.

2. Also, Password is an Access Reserved Word so if it is a field you need to enclose it in square brackets.

3. Is userid actually text or numeric? If numeric leave off the quotes.

sql = "Update USERLIST set [password]='" & Me.txt_pwd & "' where [userid]='" & Me.userid & "'"
 
Well, I'm no expert but I would replace

Code:
sql = "Update USERLIST set password='" & txt_pwd.Text & "' where userid='" & userid & "'"


With this:

Code:
sql = "Update USERLIST set password='" & txt_pwd.Text & '" where userid="' & userid & "'"
 

Users who are viewing this thread

Back
Top Bottom