zimmer9
asked on
Why does a SQL Statement execute successfully from the QUERY interface when I execute it manually but when it execute the same SQL statement from a module, I get a SQL UPDATE error?
Why do I successfully execute a SQL Statement from the QUERY interface when I execute a SQL Command manually as follows:
I update a user's password temporarily with their userID.
Update tblUserSecurity1 set password = 'zimmer9' Where userID = 'zimmer9'
However, when my Access application executes the following module after the command click event takes place, even though the same SQL Statement is executed, I get the following SQL Error:
Run-time error '-2147217900 (80040e14)': Syntax error in UPDATE statement
Private Sub Command62_Click()
Dim con As ADODB.Connection
Dim cmd As ADODB.Command
Dim strUserID As String
Set con = CurrentProject.Connection
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = con
ComboSelect = Me.Combo55.Column(1)
strUserID = " & ComboSelect & """
cmd.CommandText = "Update tblUserSecurity1 set password = '" & ComboSelect & "' " _
& "Where userID = '" & ComboSelect & "'"
Debug.Print cmd.CommandText
cmd.Execute
End Sub
-----------------------
cmd.CommandText displays the following in the Immediate Window as the result of the Debug.Print statement:
Update tblUserSecurity1 set password = 'zimmer9' Where userID = 'zimmer9'
I update a user's password temporarily with their userID.
Update tblUserSecurity1 set password = 'zimmer9' Where userID = 'zimmer9'
However, when my Access application executes the following module after the command click event takes place, even though the same SQL Statement is executed, I get the following SQL Error:
Run-time error '-2147217900 (80040e14)': Syntax error in UPDATE statement
Private Sub Command62_Click()
Dim con As ADODB.Connection
Dim cmd As ADODB.Command
Dim strUserID As String
Set con = CurrentProject.Connection
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = con
ComboSelect = Me.Combo55.Column(1)
strUserID = " & ComboSelect & """
cmd.CommandText = "Update tblUserSecurity1 set password = '" & ComboSelect & "' " _
& "Where userID = '" & ComboSelect & "'"
Debug.Print cmd.CommandText
cmd.Execute
End Sub
-----------------------
cmd.CommandText displays the following in the Immediate Window as the result of the Debug.Print statement:
Update tblUserSecurity1 set password = 'zimmer9' Where userID = 'zimmer9'
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER