Suppress the error messages

G

Guest

I use an Access form that has a button that when you click runs a query. When
I click on the button and hit cancel. I get the a box with the following
message. Run time error '2001' you cancelled the previous operation. when you
hit debug it takes me to the following code.

Private Sub Command21_Enter()
DoCmd.OpenQuery "Daily scanned", vbNormal
End Sub

I want to be able to hit cancel and not be flagged by an error message.
 
J

Jeff Boyce

Michael

One way to do this would be to turn the Warnings off. WARNING!: if you
don't turn the Warnings back on afterwards, Access could be having all kinds
of problems and you wouldn't know.

One way to turn Warnings off, run the query, and turn Warnings back on is to
do so in code, in a procedure. Another way is to use a macro to do this.

--
Regards

Jeff Boyce
Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/
 
L

Larry Daugherty

Private Sub Command21_Enter()
DoCmd.SetWarnings False
DoCmd.OpenQuery "Daily scanned", vbNormal
DoCmd.SetWarnings True
End Sub


--
-Larry-
--

Michael Kaendera said:
Jeff,
How do you turn Warnings off in Access.
message.
 
G

Guest

Larry,
I used your code and I am still getting the same error message with
the following line in yellow.
DoCmd.OpenQuery "Daily scanned", vbNormal
 
G

Guest

Michael,

You could also error trap the specific error.

Also, you could try to find the root of the problem by coding your cancel
button in such a way that the code is handled so that you never get an error
in the first place.

HTH

Aaron G
Philadelphia, PA
 
T

Tony Toews

Michael Kaendera said:
I use an Access form that has a button that when you click runs a query. When
I click on the button and hit cancel. I get the a box with the following
message. Run time error '2001' you cancelled the previous operation. when you
hit debug it takes me to the following code.

Private Sub Command21_Enter()
DoCmd.OpenQuery "Daily scanned", vbNormal
End Sub

I want to be able to hit cancel and not be flagged by an error message.

Your best solution would be to do some error handling and then ignore
the 2001 error message. Something like the following:

Private Sub Command21_Enter()

on error goto tagError

DoCmd.OpenQuery "Daily scanned", vbNormal
exit sub

tagError:
Select case err.number
case 2001 ' Ignore
case else
msgbox err.description
end select

End Sub
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
 
G

Guest

Tony,

I tried your suggestions but still did not wotk. See below.
Still getting a yellow line on the following line **


on error goto tagError

**DoCmd.OpenQuery "Daily scanned", vbNormal
exit sub

tagError:
Select case err.number
case 2001 ' Ignore
case else
msgbox err.description
end select

End Sub
 

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