PDA

View Full Version : DoCmd.SetWarnings False question



Hurrmark
06-30-2008, 10:33 AM
I am trying to run an Access macro, in which one of the functionalities is that tables are deleted and made automatically. I want to have it so the warning message that says "The existing table xxxx will be deleted before you run the query" doesn't appear. From what I read, I need to use DoCmd.SetWarnings False in my code. However, this only seems to work if I first run it through the Visual Basic editor open in Access. If I close it and run the macro, I get the warning message again. Does anyone know why this happens? Thanks.

CreganTur
06-30-2008, 11:04 AM
The command you're using is the correct one, but you may be using it incorrectly.

You'll need to wrap the code so that you turn off the warnings, and then turn them back on at the end. If you forget to turn them on, then that means you won't get any error messages, even ones you might want.

DoCmd.SetWarnings False
code steps
DoCmd.SetWarnings True


this only seems to work if I first run it through the Visual Basic editor open in Access.
I'm not sure what you mean by this. Just be sure that you enter the code to turn off warnings in the procedure where you want it, and then save your code.

Hurrmark
06-30-2008, 11:24 AM
I'm not sure what you mean by this. Just be sure that you enter the code to turn off warnings in the procedure where you want it, and then save your code.

Sorry...I meant that when I close the editor, I get the warning mesages when I run the macro. If I have it open, however, it works fine.

I don't know if this helps, but I am running the macro off a form (the button on the form, when selected, will activate the macro, which will activate the queries).

I am wondering if I placed DoCmd.SetWarnings False in the right area. I placed it in the VBA code for the macro itself rather than the form...however, I tried it both ways and it still fails.

CreganTur
06-30-2008, 11:45 AM
I am wondering if I placed DoCmd.SetWarnings False in the right area. I placed it in the VBA code for the macro itself rather than the form...however, I tried it both ways and it still fails.

That's your problem right there- Macro code is separate from Form code. They're all separate modules.

Now, you have to put it into the procedure where you need it. You can't just write it in anywhere and have it magically work.

Go to the procedure that runs the create table and delete table code. You'll want to put in the "DoCmd.SetWarnings False" at the start of that procedure, and make certain that you put the "DoCmd.SetWarnings True" and the end of the procedure!

HTH:thumb

Hurrmark
06-30-2008, 12:32 PM
That's your problem right there- Macro code is separate from Form code. They're all separate modules.

Now, you have to put it into the procedure where you need it. You can't just write it in anywhere and have it magically work.

Go to the procedure that runs the create table and delete table code. You'll want to put in the "DoCmd.SetWarnings False" at the start of that procedure, and make certain that you put the "DoCmd.SetWarnings True" and the end of the procedure!

HTH:thumb

Thanks...this helps!