Solved Setfocus to newly added record in subform (1 Viewer)

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:13
Joined
Feb 19, 2002
Messages
42,986
There are two macros I have in every application and I don't use macros for anything else.

mSetWarningsOff

mSetWarningsOn

The reason I use macros to toggle warnings is because it is EXTREMELY dangerous to leave warnings off accidentally. You could easily loose hours of work if you closed an object without explicitly saving it first, having warnings off would suppress the "do you want to save?" message and Access would silently discard your changes. This is only a problem when you are testing. If you stop the code in the section between the Off and On, the Warnings are Off but having the Hourglass on reminds you that warnings are off so you can immediately turn them back on.

Each macro has two commands. The "off" turns Warnings Off and the Hourglass On and the "on" turns Warnings On and the Hourglass Off.

Having the Hourglass on is sufficiently annoying that you know you need to turn it off. Using macros rather than code gives you an easy place to turn the warnings back on by running the "On" macro.
 

cheekybuddha

AWF VIP
Local time
Today, 15:13
Joined
Jul 21, 2014
Messages
2,238
David, you might have missed the posted code in post#1 but it does have the DoCmd.SetWarnings True near the bottom. I think you were looking at Arnelgp's code which I'm not using. Thank you for your concern though. Very thoughtful.
Yes, I did miss it when I read your original post. 😬 I noticed that Arnelgp had omitted it too and guessed it was because he based his code on yours.

A much better practice when using action queries is to use CurrentDb.Execute. Then you have no need to turn off the warnings.

in fact, I can't remember ever needing to use SetWarnings False.

hth,

d
 

Mike Krailo

Well-known member
Local time
Today, 11:13
Joined
Mar 28, 2020
Messages
1,032
Thanks David. This is all great advice. I just recently started using the CurrentDb.Execute in other projects and didn't even realize that particular advantage about the warnings.
 

Users who are viewing this thread

Top Bottom