I have a quirk with my Access app that I cannot debug.
I have a form that essentially makes an insertion into a ‘completed’ table and a deletion from a ‘pending’ table. Design preferences aside, this is how I’m doing it rather than having some sort of ‘Status’ column.
I’ll summarize my code with the relevent lines.
First it makes the insertion into the completed table, then the simple deletion:
qr = "DELETE * FROM tblPendingClasses WHERE ((tblPendingClasses.ID = " & curr & "));" 'build the query
Debug.Print qr
MsgBox (qr)
dbMine.Execute qr, dbFailOnExecute
Form.Refresh 'refresh,requery
Form.Requery
MsgBox ("Class review complete.")
docmd.close
The query is built fine, from the debug statement and msgbox, but it just doesn’t do anything. I look at the table for pending classes, and the class with the ID I’m trying to delete is just sitting there. No meaningful errors, nothing. This used to work, and works sometimes, but is not working at the moment.
Ideas?
If your module includes
Option Explicit, you should get a compile error, “Variable not defined” on this line:Probably you intended
dbFailOnErrorinstead ofdbFailOnExecuteas the option for the.Executemethod. AddOption Explicitto the Declarations section of your code module so the VBA compiler will alert you when you attempt to use the name of a constant which doesn’t exist (dbFailOnExecute). Then compile and fix any other issues the compiler complains about.The Database.Execute Method help topic recommends:
“… always use the dbFailOnError option when using the Execute method to run an update or delete query. This option generates a run-time error and rolls back all successful changes if any of the records affected are locked and can’t be updated or deleted.“
So
dbFailOnExecutewill give you the run-time error message which explains why the expected deletions didn’t happen.After making those changes, if you still don’t get any rows deleted and no error message, make sure you don’t have
SetWarningsswitched off.