db.execute code doesnt seem to run

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
 
A

Allen Browne

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
 
R

Rodrigo

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top