Results 1 to 3 of 3
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    How to pause or wait n seconds

    I found this old thread.


    https://www.accessforums.net/showthr...0903#post10903

    Odd it never got answered.
    I've hunted around in Google for a solution, haven't found one that works (some 64-bit error)
    Avoid Using DoEvents to Wait in Microsoft Access, VBA, and VB6 (fmsinc.com)

    There must be a command to pause execution.
    What is it?

  2. #2
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    And I finally found the solution:

    Code:
    Option Compare Database
    Option Explicit
    
    
    #If VBA7 Then
        Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
    #Else
        Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    #End If
    
    
    Public Sub mySleep(Optional Seconds As Double = 1, Optional AllowDoEvents As Boolean = True)
        ' this function will break up seconds into quarters of a second
        Dim SecFrac As Double
        SecFrac = 0
        While SecFrac < Seconds
            Sleep 250
            If AllowDoEvents Then DoEvents
            SecFrac = SecFrac + 0.25
        Wend
    End Sub

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    no need for the longptr - it is still long for VBA7. Using it might cause problems as potentially the wrong amount of memory will be read

    longptr is only required for pointers such as hwnd

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

Similar Threads

  1. Pause / Wait / Countdown / Timer
    By DevGreg in forum Programming
    Replies: 2
    Last Post: 07-19-2022, 06:30 AM
  2. Replies: 4
    Last Post: 07-04-2017, 12:23 AM
  3. Replies: 3
    Last Post: 08-27-2015, 06:18 PM
  4. Making code wait/pause until event
    By faythe1215 in forum Programming
    Replies: 3
    Last Post: 02-09-2015, 03:44 PM
  5. Pause state?
    By Zermoth in forum Programming
    Replies: 1
    Last Post: 12-15-2008, 05:05 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