I am working through the test taker database in developer series. When I press the begin test button, I get an information message box pop up saying I am about to append a row. Selecting yes runs the SQL. Selecting no creates an error. "Runtime error 2501, RunSQL action was cancelled." I have replicated the code in the instruction video exactly. The video never prompts the user for a yes/no action. What am I doing wrong?
Kevin Robertson
@Reply 4 days ago
Click Debug and change the highlighted code to this:
On Error Resume Next
DoCmd.RunSQL S
On Error GoTo 0
Yeah, I'm pretty sure this was covered in one of the earlier classes. DoCmd.RunSQL has confirmation warnings enabled by default, which is why you're seeing the "You are about to append..." message. Clicking No cancels the action and produces error 2501.
Kevin's fix will suppress the error, but I generally prefer using CurrentDb.Execute for action queries now. It doesn't display the Access confirmation prompt in the first place, and it gives you better control over error handling.
Yes, even I learned a thing or two over the production of this course that spans 20+ years. LOL. There's nothing wrong with using RunSQL, but Execute will bypass all that warning nonsense.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.