Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    Kansas, USA
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Without confirming msgbox

    Using Access 2000, is it possible to bypass the "You are about to delete records, etc" messages when running action queries by the VBA docmd.openquery or when using the docmd.runSQL method? I have used Sendkeys "Y", but is there a better way?

  2. #2
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Massachusetts
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Without confirming msgbox

    Use Setwarnings:

    DoCmd.SetWarnings False
    DoCmd.RunSQL
    DoCmd.SetWarnings True

    Note: YOU MUST turn the warnings back on, or a lot of problems may result. I strongly recommend turning them off perform the action, then turn them on. Also, I would not group actions in between, perform one action per off / on. ( A bit more overhead, but less chance of missing important errors)

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Without confirming msgbox

    The other way, which is faster but sometimes chokes on a single action query for no apparent reason, is to use the Execute method on the database or querydef object. Here's an example:

    <pre> Dim dbs as DAO.Database
    Set dbs = CurrentDb
    dbs.Execute strSQL
    ...
    Set dbs = nothing</pre>



    The Execute method doesn't pop up the confirmation message at all, so you don't need to set warnings off and on.
    Charlotte

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Without confirming msgbox

    I agree with you Charlotte, but the execute method will not give you any message at all! Normally you still want to raise an error if th SQL is not correct. You have to add a switch to be sure an error is raised:

    Dim dbs as DAO.Database
    Set dbs = CurrentDb
    dbs.Execute strSQL, dbFailOnError
    ...
    Set dbs = nothing

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Without confirming msgbox

    You're absolutely right, and I intended to mention error handling in my post, but I was doing several other things at the same time and obviously slipped up on that one. Thanks for pointing it out![img]/w3timages/icons/grin.gif[/img]
    Charlotte

Posting Permissions

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