Microsoft Excel Webinar

Results 1 to 5 of 5

Thread: DoCmd.SetWarnings False question

  1. #1

    DoCmd.SetWarnings False question

    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.

  2. #2
    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.

    VB:
    DoCmd.SetWarnings False 
    code steps 
    DoCmd.SetWarnings True 
    
    
    Formatting tags added by mark007
    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.
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  3. #3
    Quote Originally Posted by CreganTur

    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.

  4. #4
    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
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  5. #5
    Quote Originally Posted by CreganTur
    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
    Thanks...this helps!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •