Consulting

Results 1 to 5 of 5

Thread: Pausing between code

  1. #1
    VBAX Regular
    Joined
    Jul 2004
    Posts
    19
    Location

    Pausing between code

    Hi there,

    Can anybody tell me how to write some code to pause in between other code.

    I have written some code to open a word document, merges with 100 records (takes 4 minutes) then opens another word document, merges again etc etc. I have 15 word documents and if the code run one after another, I am getting all sorts of errors through word.

    I want to be able to pause: 50000 (i.e. 5 minutes) then run next code.

    Any ideas would be appreciated.

    Smilla

  2. #2
    VBAX Regular ___'s Avatar
    Joined
    Jun 2004
    Posts
    22
    Location
    Try using this function (Code by G.Hudson)
    [vba]
    Public Function Pause(NumberOfSeconds As Variant)
    On Error GoTo Err_Pause


    Dim PauseTime As Variant, Start As Variant

    PauseTime = NumberOfSeconds
    Start = Timer
    Do While Timer < Start + PauseTime
    DoEvents
    Loop

    Exit_Pause:
    Exit Function

    Err_Pause:
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_Pause

    End Function

    [/vba]
    and call it like...
    Pause (5)
    for a five second pause.

    HTH
    Nemo hic adest illius nominis
    ??????????????????
    ??????

  3. #3
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    [vba]

    Application.Wait Now + TimeSerial(0, 5, 0)

    [/vba]
    Also check out Application.OnTime

    {Edit} I didn't realize this was for Access. Disregard.

  4. #4
    VBAX Regular
    Joined
    May 2004
    Location
    Sydney, Australia
    Posts
    36
    Location
    Quote Originally Posted by DRJ
    [vba]

    Application.Wait Now + TimeSerial(0, 5, 0)

    [/vba]

    Also check out Application.OnTime
    DRJ, they are Excel methods and aren't available in Access.

    Regards,
    Daniel

  5. #5
    VBAX Regular
    Joined
    Jul 2004
    Location
    San Bernardino, California
    Posts
    69
    Location
    Or you can try this Sleep API:

    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilleseconds As Long)
    Then call it like this
    Sleep 5000
    HTH, Thanks.

Posting Permissions

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