This may help...
Function Delay%(sglDelayIntvl As Single)
'===========================================================
'
' Desc: This function delays for N 1/100's seconds.
' This is necessary because some screen flips free the
' Presentation Space a second before the next
' screen arrives.
'
' The Windows Sleep API is called to execute the
' delay. This API is recommended for 32 bit
' Visual Basic applications for "Waiting" in code.
'
' DoEvent statements are still issued so that: the
' "Busy" Form is updated by allowing the Timer
' control some time; and allow Windows to be more
' responsive to mouse events and painting, etc.
'
' Parms: sglDelayIntvl - number of seconds to wait before returning.
'
' Returns: 0 - Successful
' ELP_INVALID_WAIT_INTVL - Delay is not between 0 - 60 seconds
'
'===========================================================
On Error GoTo Delay_Err
Const OAS_MAX_WAIT_SECS = 60# 'Maximum wait allowed is 60 seconds
Const DELAY_INTERVAL = 250 'Default delay interval (.25 seconds/250 Milliseconds)
Dim sglStartTime As Single
Dim sglEndTime As Single
Dim sglElapsedTime As Single
Dim lngdelay As Integer
If Not ((sglDelayIntvl > 0) And (sglDelayIntvl < OAS_MAX_WAIT_SECS)) Then
Delay% = ELP_INVALID_WAIT_INTVL
Exit Function
End If
' Convert delay time to the format (milliseconds) needed by the Sleep API
lngdelay = sglDelayIntvl * 1000
sglStartTime = Timer
' Wait for specified amount of time, but issue DoEvents at regular
' intervals, in order for forms to be updated and mouse events to
' be processed.
Do While (lngdelay > 0)
If (lngdelay > DELAY_INTERVAL) Then
Call Sleep(DELAY_INTERVAL)
lngdelay = lngdelay - DELAY_INTERVAL
Else
Call Sleep(lngdelay)
lngdelay = 0
End If
' Allow forms to be updated and mouse events to be processed
DoEvents
Loop
sglEndTime = Timer
sglElapsedTime = sglEndTime - sglStartTime
gsglElapsedTime = sglEndTime - gsglStartTime
Debug.Print "Delay, executed for time of "; sglElapsedTime; Space(4); "Split Time: "; gsglElapsedTime
Delay% = 0
Exit Function
Delay_Err:
Call KillTheScript(Err, "Delay", "", True)
End Function