?
Solved

How to resolve the error "Run-time error '-2147217900(80040e14): Synax error in UPDATE statement using Access 2003?

Posted on 2013-07-01
6
Medium Priority
?
5,974 Views
Last Modified: 2013-07-01
I am developing an Access application in Access 2003 using an MDB type file.

In the following VBA code, I am getting the error:

Run time error '-2147217900(80040e14);
Syntax error UPDATE statement.
Do you know how I can resolve this error?

And I performed the following display while debugging my code:
?ssql
update tblUserSecurity1 set password= 'Martin29' WHERE recordnum='1'

recordnum is an AutoNumber Data Type field.

Private Sub Command34_Click()
    Dim strSQL As String
    Dim strSQLFull As String
    Dim ssql As String
    Dim rst As ADODB.Recordset
    Dim con As ADODB.Connection
    If Me.TxtPwd.Value = DLookup("password", "tblUserSecurity1", "[recordnum]=" & Me.Combo25.Value) Then
    Else
       MsgBox "Incorrect password!"
       Exit Sub
    End If
    If Nz(Me!Text28, "") <> Nz(Me!Text30, "") Then
       MsgBox "Passwords don't match!"
       Exit Sub
    End If
    If Nz(Me!Text28, "") = "" Then
       MsgBox "Please type in a new password!"
       Exit Sub
    End If
 
    Set con = CurrentProject.Connection
    Set rst = New ADODB.Recordset
    ssql = "update tblUserSecurity1 set password= '" & Me!Text28 & "' WHERE recordnum='" & Me!Combo25.Value & "'"
    rst.Open ssql, con
End Sub
0
Comment
Question by:zimmer9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Author Comment

by:zimmer9
ID: 39291916
Guess the answer is the autonumber should not be in quotes
0
 

Author Comment

by:zimmer9
ID: 39291925
ssql = "update tblUserSecurity1 set password= '" & Me!Text28 & "' WHERE recordnum= " & Me!Combo25.Value & ""
rst.Open ssql, con

generates:

?ssql
update tblUserSecurity1 set password= 'Martin29' WHERE recordnum= 1

yet I still get the same error:
Run time error '-2147217900(80040e14);
Syntax error UPDATE statement.
0
 

Author Comment

by:zimmer9
ID: 39291933
However, if I place the following:

update tblUserSecurity1 set password= 'Martin29' WHERE recordnum= 1

manually in a query object, the code works. The system states:
You are about to update 1 row(s)
Once you click YES, you can't use the UNDO command to reverse the changes.
Are you sure you want to update these records.
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 9

Expert Comment

by:edtechdba
ID: 39291937
Are you all set? If not, you may want to check out this update statement, it should work.

    ssql = "UPDATE tblUserSecurity1 SET password = '" & Me!Text28.Value & "' " & _
            "WHERE recordnum = '" & Me!Combo25.Value & "'"
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39291967
You're right about the recordnum not being in quotes; so you don't need the ending quotes either:
ssql = "update tblUserSecurity1 set password= '" & Me!Text28 & "' WHERE recordnum= " & Me!Combo25.Value
This section
    If Me.TxtPwd.Value = DLookup("password", "tblUserSecurity1", "[recordnum]=" & Me.Combo25.Value) Then
    Else
       MsgBox "Incorrect password!"
       Exit Sub
    End If

Open in new window

can be shortened this way:
    If Me.TxtPwd.Value <> DLookup("password", "tblUserSecurity1", "[recordnum]=" & Me.Combo25.Value) Then
       MsgBox "Incorrect password!"
       Exit Sub
    End If

Open in new window

I don't see the need for a recordset since you are not doing anything with it.  To run an Update SQL statement you need to use the Execute method.
So your whole code can be shortened to this:
    If Me.TxtPwd.Value <> DLookup("password", "tblUserSecurity1", "[recordnum]=" & Me.Combo25.Value) Then
       MsgBox "Incorrect password!"
    Else If Nz(Me!Text28, "") <> Nz(Me!Text30, "") Then
       MsgBox "Passwords don't match!"
    Else If Nz(Me!Text28, "") = "" Then
       MsgBox "Please type in a new password!"
    Else 
        Set con = CurrentProject.Connection
        ssql = "update tblUserSecurity1 set password= '" & Me!Text28 & "' WHERE recordnum= " & Me!Combo25.Value
        con.Execute ssql
    End If

Open in new window

0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 39292028
try placing the word "password" in brackets


ssql = "update tblUserSecurity1 set [password]= '" & Me!Text28 & "' WHERE recordnum= " & Me!Combo25.Value
0

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question