Access VBADiscuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
Public Function fnWait(intNrOfSeconds As Integer)
Dim varStart As Variant
varStart = Timer
Do While Timer < varStart + intNrOfSeconds
Loop
End Function
This works perfectly, when you are accessing a database via VBA on Excel and then you want to perform some calcutions in VBA right after the table is returned.
So to the author of the script, thank you very much.
FHanFreeman
13-Feb-2010.
It's worth mentioning that looping with DoEvents in the middle is going to tie up your CPU, using the API method will not.
Code:
Private Declare Sub APISleep Lib "kernel32" Alias "Sleep" (ByVal lngMilliseconds As Long)
Public Function Sleep(lngSeconds As Long) As Boolean
If lngSeconds > 0 Then
Call APISleep(lngSeconds * 1000)
Sleep = True
End If
End Function
Why not just try "For loop structure", something like
For j = 1 To 10000000
Next j
it can be last for a while.
hope it can be helpful
The problem with this approach is that it will not give you constant results for the amount of delay.
Back in the days of the first PC's ( old XT's) your method was a common practice. Then the 286 machines cam out. The processor were so much faster that the loops like you suggest we being performed very fast. Games were executing so fast the human could not keep up. You have to run a special program to script the processor to slow it down enough that a humans could keep up. Games had to be rewritten to pause based in the passing of time. Once this method was used games were still be playable on the newer and faster CPUs.