?
Solved

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

Posted on 2006-06-06
3
Medium Priority
?
4,614 Views
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?

Cheers
0
Comment
Question by:Andy1
  • 2
3 Comments
 
LVL 11

Expert Comment

by:pootle_flump
ID: 16841612
I use this:

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

Don't know if anyone has anything better.

HTH
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 2000 total points
ID: 16841731
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
0
 
LVL 11

Expert Comment

by:pootle_flump
ID: 16841783
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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
A quick solution showing how to control and open a POS Cash Register Drawer using VBA with MS Access.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

571 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