Results 1 to 7 of 7
  1. #1
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245

    Running queries, VIA VB, but not running in Order

    Hey, I have this set up to run a sequence of events on a button click.



    all events run, however not in the proper order. how can adjust it to go in the right order? (I have it listed in the order I want)

    Code:
    'Run Append Temp Monthly Returns,
    'Delete NonNumeric Values
    DoCmd.SetWarnings False
    CurrentDb.Execute "qryDeleteTempNullReturns", dbfailonExecute
    DoCmd.OpenQuery "qryAppendTempMonthlyReturns", acViewNormal
    CurrentDb.Execute "qryAppendMonthlyReturns", dbfailonExecute
    DoCmd.OpenQuery "qryDeleteTempMonthlyReturns", acViewNormal
    DoCmd.SetWarnings True
    thanks,

  2. #2
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    As Dal said, it should be dbFailonError. And With

    CurrentDb.Execute "qryDeleteTempNullReturns", dbfailonError

    you should not be using the SetWarnings False. SetWarnings True
    That's a feature of dbFailOnError, if an error, then you'll get a message, if no error no message.

    Good luck.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by orange View Post

    ...you should not be using the SetWarnings False. SetWarnings True
    That's a feature of dbFailOnError, if an error, then you'll get a message, if no error no message.
    But he's not using CurrentDb.Execute to run all of his Queries, is he?

    Access is asynchronous, which is to say, if given a series of commands, it starts to execute one, moves on to the next one and starts executing it, and so forth. It doesn't wait for the first command to be completed before starting the second one, and this can cause timing problems.

    An prime example of this would be the very situation you describe; a button that runs a series of Queries where all but the first Query is dependent upon the previous Query being completed before it starts to execute. The following VBA code

    Code:
    DoCmd.OpenQuery "QueryA"
    DoCmd.OpenQuery "QueryB"
    DoCmd.OpenQuery "QueryC"
    will immediately run all three, not waiting for one to finish executing before starting the next one. The answer to halting the code in this type of situation is to use DoEvents.

    Code:
    DoCmd.OpenQuery "QueryA"
    DoEvents
    DoCmd.OpenQuery "QueryB"
    DoEvents
    DoCmd.OpenQuery "QueryC"

    DoEvents returns control to Windows, allowing QueryA to complete running before starting to run QueryB. It then allows QueryB to finish running before starting QueryC.

    DoEvents is an easy, safe bet when encountering this type of timing issues.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    But he's not using CurrentDb.Execute to run all of his Queries, is he?
    Not all, but he is doing some of each

    Code:
    DoCmd.SetWarnings False 
    CurrentDb.Execute "qryDeleteTempNullReturns", dbfailonExecute 
    DoCmd.OpenQuery "qryAppendTempMonthlyReturns", acViewNormal 
    CurrentDb.Execute "qryAppendMonthlyReturns", dbfailonExecute 
    DoCmd.OpenQuery "qryDeleteTempMonthlyReturns", acViewNormal 
    DoCmd.SetWarnings True

  6. #6
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245
    Thanks for the help!

  7. #7
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124

    Running set of queries in certain order

    Quote Originally Posted by mike02 View Post
    Thanks for the help!
    I was wondering if you could call a function with a Boolean return value for example [Code]
    (This is pseudocode)
    If Func1Qry1 then
    If Func2Qry2 then
    If Func3Qry3 then
    Where Func1Qry1(qry as Query)as Boolean etc. Can this avoid the asynchronous behavior of MSAccess?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Running Queries from a form
    By HaYuM in forum Queries
    Replies: 1
    Last Post: 08-23-2013, 03:12 AM
  2. macro running in order
    By dumbledown in forum Access
    Replies: 2
    Last Post: 09-03-2012, 08:05 AM
  3. Replies: 11
    Last Post: 07-08-2011, 02:12 PM
  4. Running sum in queries
    By sankarkunnath in forum Queries
    Replies: 0
    Last Post: 10-24-2010, 12:26 PM
  5. Running parameter queries from VBA
    By John Southern in forum Programming
    Replies: 6
    Last Post: 03-25-2010, 10:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums