954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

i got syntax error in update statement

Guys i always get an error in this...it says "Syntax error in Update Statement"
please help...

Sub updateaccount(ByVal Username As String, ByVal Password As String, ByVal FName As String, ByVal MName As String, ByVal LName As String, ByVal Restrict As String, ByVal FullName As String)
        connect = New ADODB.Connection
        rs = New ADODB.Recordset
        Dim rss As New ADODB.Recordset
        connect.ConnectionString = "PROVIDER=Microsoft.JET.OLEDB.4.0;Data Source=C:\Users\Spongebob\Desktop\DataBase1.mdb"
        connect.Open()

        Dim sql1, sql As String

        sql = "Select AUsername from AdminAccount"
        rs.Open(sql, connect, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockPessimistic)

        If Username = "" Or Password = "" Or FName = "" Or MName = "" Or LName = "" Then
            MsgBox("Input asked values.")
        Else
            sql1 = "UPDATE AdminAccount where (AUsername = '" & Trim(Username) & "') set (APassword = '" & Trim(Password) & "', AFName ='" & Trim(FName) & "', AMName ='" & Trim(MName) & "', ALName ='" & Trim(LName) & "', Restrict? ='" & Trim(Restrict) & "', AFullName ='" & Trim(FullName) & "')"
            rss.Open(sql1, connect, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockPessimistic)
            MsgBox("Change(s) of the Account " & Username & " was saved!")
        End If

    End Sub
amf101
Newbie Poster
9 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

Before executing take the query and run in sql server so u will come to know where the syntax is going wrong..

Pgmer
Master Poster
714 posts since Apr 2008
Reputation Points: 54
Solved Threads: 121
 

I'm fairly certain that you have to put the "SET" clause before the "WHERE" clause. That's fairly standard SQL syntax, even MSAccess SQL.
Here's some sample syntax that you can adapt to your specific situation:

UPDATE MyTable 
SET MyTable.MyNumeric = 100
WHERE (((MyTable.MyCharacter)="One")) 
OR (((MyTable.MyCharacter)="Two"));

One other little thing...on line 16, there appears to be a superfluous question-mark after the column name "Restrict". Probably has nothing to do with your syntax problem, but you might want to check into it anyway.

Hope this helps! Good luck!

BitBlt
Master Poster
711 posts since Feb 2011
Reputation Points: 367
Solved Threads: 109
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: