Consulting

Results 1 to 4 of 4

Thread: Solved: Allowing time for the SQL query to fully run

  1. #1
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location

    Solved: Allowing time for the SQL query to fully run

    Hi there,

    I have some code that has been an issue in the past that i ended up wasting hours trying to figure out ... the need to use this type of code has come up again, so i thought i would reach out to the smartest audience in VBA.

    What i am trying to do, is allow the below code to execute without skipping past the query completion/refresh. It waits, but then finishes the code and the data when i go back in hasnt actually refreshed ....

    thoughts? Is there a way to purposefully add a delay? The query takes about 1 minute to run.

    [VBA]
    Private Sub Workbook_Open()
    'Application.Wait Now + TimeSerial(0, 0, 10)
    Dim WAIT As Double
    WAIT = Timer
    While Timer < WAIT + 5
    DoEvents 'do nothing
    Wend

    'Application.ScreenUpdating = False

    'code start here

    Refresh.Refresh 'refresh the data


    Mail_Selection_Range_Outlook_Body 'send via outlook

    'code end here


    'Application.ScreenUpdating = True



    Application.DisplayAlerts = False
    'quit excel and dump memory
    ActiveWorkbook.Save
    Dim appExcel As Excel.Application
    Set appExcel = GetObject(, "Excel.Application")
    appExcel.Quit
    Set appExcel = Nothing

    End Sub
    [/VBA]
    Last edited by debauch; 04-16-2013 at 09:54 AM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    [VBA] While Timer < WAIT + 5 'Wait 5 seconds
    While Timer < WAIT + 60 'Wait 1 minute
    [/VBA]
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    set the querytable's property backgroundquery=false

  4. #4
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location
    Quote Originally Posted by snb
    set the querytable's property backgroundquery=false
    I was missing this property ... thank you!!

Posting Permissions

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