Results 1 to 5 of 5
  1. #1
    coach32 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    47

    Code seems to freeze Access

    I have the following code attached to a command button on my Form.
    When the button is pressed, the queries should update (which they do) and the
    database closes down. The database however doesn't shut down, but when I click
    around the database anywhere, it finally vanishes. Is there sonething I need to
    include in the code?
    Thank you for any advice you can offer.
    Code:
    Private Sub Command29_Exit(Cancel As Integer)
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "1"
    DoCmd.OpenQuery "2"
    DoCmd.OpenQuery "3"
    DoCmd.OpenQuery "4"
    DoCmd.OpenQuery "5"
    DoCmd.OpenQuery "6"
    DoCmd.OpenQuery "7"
    DoCmd.OpenQuery "8"
    DoCmd.OpenQuery "9"
    DoCmd.OpenQuery "10"
    DoCmd.OpenQuery "11"
    DoCmd.OpenQuery "12"
    DoCmd.OpenQuery "13"
    DoCmd.SetWarnings True
    DoCmd.Quit
    End Sub


  2. #2
    trevor40's Avatar
    trevor40 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    407
    What happens if setwarnings is set to true?
    try on error resume next in place of setwarnings = false, 'just the first one, don't use the second setwarnings it does nothing as you are closing the DB

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe use this instead?

    Code:
     
    Dim db As DAO.Database
    Set db = CurrentDb
    
    db.Execute "1"
    db.Execute "2"
    db.Execute "3"
    db.Execute "4"
    db.Execute "5"
    db.Execute "6"
    db.Execute "7"
    db.Execute "8"
    db.Execute "9"
    db.Execute "10"
    db.Execute "11"
    db.Execute "12"
    db.Execute "13"
    
    Set db = Nothing
    
    DoCmd.Quit
    It sounds like a RAM issue with the PC that is running the queries. If you still have performance issues maybe you can run the queries off peak hours by dedicating a machine to it and using Task Scheduler to open an Access File.

  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
    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. I expect that this is what is causing your problems; you're either outstripping your processor's capabilities, by running 13 Queries, back-to-back, as ItsMe suggested, or one or more Queries depend on values returned by the previous Query. Here's a quick tutorial I've given people who were experiencing this problem:

    An example would be 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.


    Linq ;0)>

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Forgot about DoEvents

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

Similar Threads

  1. VBA MsgBox Print .Echo Freeze
    By Jester0001 in forum Programming
    Replies: 4
    Last Post: 05-18-2012, 05:03 PM
  2. Freeze or Lock data after querried
    By Dannat in forum Queries
    Replies: 1
    Last Post: 01-25-2012, 10:30 PM
  3. Freeze panes in reports
    By Jamy in forum Reports
    Replies: 4
    Last Post: 01-02-2012, 03:19 PM
  4. Freeze Columns in a Form?
    By Paul H in forum Forms
    Replies: 9
    Last Post: 09-09-2011, 01:40 PM
  5. using VBA to freeze columns
    By bdaniel in forum Forms
    Replies: 1
    Last Post: 02-12-2010, 05:36 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