Access VBA - Need to wait a few seconds...

Posted on 2006-06-06
Last Modified: 2008-01-09
Im running a section of code in a modle and if my program encounters an error accessing a peice of data, I have it change a status lable to read "Data Access Failed Waiting 5 seconds before trying again..."

I've go this all set so that it will only retry 3 times before giving up attempting to auto access the data.

Whats the best way to setup a timer to wait for 5 seconds before continuing?

Question by:Andy1
    LVL 11

    Expert Comment

    I use this:

    Public Sub PauseApp(PauseInSeconds As Single)
        Dim sngStart As Single
        sngStart = Timer
        Do While sngStart + PauseInSeconds > Timer
    End Sub

    Don't know if anyone has anything better.

    LVL 44

    Accepted Solution

    Hi Andy1,

    Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

    In the declarations section then:

    Sleep 5000

    Where you need to wait. This causes the thread to sleep for a period of time. This may be a better solution as a tight loop could increase processor usage and not allow your other applications to run.

    If you use the tight loop approach, ensure that you also use DoEvents to release the processor inside the loop.

    Tim Cottee
    LVL 11

    Expert Comment

    Yep - I like Tim's solution. Put it this way - I will be changing my function in my app. Always thought it was quick and dirty but never got round to checking out for something better.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
    With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now