Change Password SQL Error on Windows Form App

I'm trying to make a function where the user can change their password.  I have written the following code but kep getting an error 'OleDbException was unhandled' ' Syntax error in UPDATE statement'.

Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database.accdb")
        Dim cmd As OleDbCommand = New OleDbCommand("UPDATE UserTable SET Password='" & TextBox2.Text & "' WHERE UserID='" & "'Module1.currentUser'", con)
        con.Open()


        Dim affectRow As Integer = cmd.ExecuteNonQuery()

        If affectRow <> 0 Then
            MessageBox.Show("Password changed successfully!")
            MainMenu.Show()
            Me.Close()

        End If

Can anyone solve the error?
koldjgAsked:
Who is Participating?
 
mvgeertruyenConnect With a Mentor Commented:
In SQL this should work - you can try to enclose userid and password between brackets; they might be reserved words.
"UPDATE UserTable SET [Password]='" & TextBox2.Text & "' WHERE [UserID]='" & Module1.currentUser & """
Copy to error to the cliboard and see if it give more information about the syntax.

rgds

0
 
mvgeertruyenCommented:
Change

WHERE UserID='" & "'Module1.currentUser'", con)

to

WHERE UserID='" & Module1.currentUser & """, con)

0
 
koldjgAuthor Commented:
I still get the same error.  Heres a screenshot

http://img4.imageshack.us/img4/9963/screenshotbhn.jpg 
0
 
koldjgAuthor Commented:
Yes that worked, thanks a lot for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.