Returning current SetWarnings value

G

Guest

Hi, everyone!

Have a sub that performs a MakeTable query. When it runs, I never want to
show the Warnings. Easy enough, just DoCmd.SetWarnings = False.

This sub is called in various places. Sometimes, Warnings are on and at
other times they are already off. In the sub, I want to be able to find out
the current SetWarnings value, turn SetWarnings off to run the MakeTable
query, then return SetWarnings to the value it had before the sub was called.


Can't seem to find how to read the current value of SetWarnings. Anyone
know how?

Thanks,
Bruce
 
A

Allen Browne

Unfortunately, Access does not provide a way to read the status of
SetWarnings.

I guess you could create a global boolean, and set it whenever you actually
change SetWarnings, so you can read your variable to know where you are up
to.

But there is a better way than using SetWarnings anyway. If you do stuff
like:
DoCmd.SetWarnings = False
DoCmd.RunSQL "INSERT INTO ...;"
then you have no way of knowing if the action query succeeded or failed.
Once you turn SetWarnings off, you're stuck.

A better approach would be:
dbEngine(0)(0).Execute "INSERT INTO ...;", dbFailOnError
This way you do not need to toggle SetWarnings: no message is generated if
everything goes well. But if there is a problem, it generates an error that
you can trap and respond to.
 
G

Guest

Thanks, Allen! Good suggestion.
Bruce

Allen Browne said:
Unfortunately, Access does not provide a way to read the status of
SetWarnings.

I guess you could create a global boolean, and set it whenever you actually
change SetWarnings, so you can read your variable to know where you are up
to.

But there is a better way than using SetWarnings anyway. If you do stuff
like:
DoCmd.SetWarnings = False
DoCmd.RunSQL "INSERT INTO ...;"
then you have no way of knowing if the action query succeeded or failed.
Once you turn SetWarnings off, you're stuck.

A better approach would be:
dbEngine(0)(0).Execute "INSERT INTO ...;", dbFailOnError
This way you do not need to toggle SetWarnings: no message is generated if
everything goes well. But if there is a problem, it generates an error that
you can trap and respond to.
 

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