db.execute code doesnt seem to run

  • Thread starter Thread starter Steven Scaife
  • Start date Start date
S

Steven Scaife

Hi there thanks for the help so far its been much appreciated. However i
have an if statement that executes but the db.execute doesnt enter any data
into the tables.

I know the if statement runs cos i get the msgbox then in the immediate
window i can see that the recordset is populated, and strvariable has the
correct value. then when execution carries onto the db.executes the sql
code doesnt seem to run and i cant understand why, no error is given it just
seems to run, but when i check my tables they are empty. Any help would be
greatly appreciated.

If cboPayMethod.Value = "Credit Card" Then
MsgBox "running the CCard Code"
strsql = "SELECT TOP 1 Payment_ID FROM Payment ORDER BY Payment_ID
DESC;"
Set rs = db.OpenRecordset(strsql)
strvariable = rs!Payment_ID
db.Execute "INSERT INTO Payment_Merge (Payment_ID, Card_Number)
Values (" & strvariable & ", " & Me.txtCard & ");"
db.Execute "INSERT INTO Card_Info (Card_Number, Card_Type,
Issue_Number, Expiry_Date) VALUES (" _
& Me.txtCard & ", '" & Me.cboCardType & "', " & Me.txtIssue & ", '"
& Me.txtExpiry & "');"
Else
MsgBox "CCard code not run"
End If
 
Use the dbFailOnError switch so you are notified of any errors.
Then check the RecordsAffected to see how many records were inserted.

db.Execute "INSERT ...;", dbFailOnError
Debug.Print db.RecordsAffected
 
It looks like you are missing the extra quotes for the string values.
db.Execute "INSERT INTO Payment_Merge (Payment_ID, Card_Number) Values (" &
strvariable & ", " & Me.txtCard & ");"

db.Execute "INSERT INTO Payment_Merge (Payment_ID, Card_Number) Values ('" &
strvariable & "', '" & Me.txtCard & "');"

Rodrigo.
 
Back
Top