action query warning trapping

sierra467

Registered User.
Local time
Today, 18:13
Joined
Aug 1, 2005
Messages
66
Hi there,

I like having the action query warning appear with what I am doing - "You are about to update xxx rows". The problem that I am having is that when my RunSQL statement in the code executes and selects no to the warning, I get the error -

Run-time Error '2501'
The RunSQL action was canceled.

How can I trap the no selection so that this vba error does not appear?
 
I was looking for something like how you might handle a msgbox() function by programing for vbYes or vbNo but I could not find anything like this
Code:
if msgbox("Do you want to continue?", vbYesNo, "Continue?") = vbYes then 
    msgbox"Yippeeee!"
else
    msgbox"Bummer!"
end if

So the answer I settled on was using an error handler which seems a little strange but it worked. This is what I did

Code:
Private Sub cmdErrors_Click()
On Error GoTo ErrHandler
    
    DoCmd.RunSQL "UPDATE tblData SET fldName = '" & Me.txtNewName & "' WHERE fldName = '" & Me.txtName & "';"
    Me.txtNewName = ""
    Me.txtName.Requery
    
ErrHandler:
    Me.txtNewName.SetFocus
    Exit Sub

End Sub
 

Users who are viewing this thread

Back
Top Bottom