DoCmd.wait for 5 seconds

W

Wayne-I-M

Hi

Is there a way to get a form to do nothing for a few seconds on open.

I am running a small module on open but it fails if the code runs right away
(as it is querying other forms that take a second to open - but the module
runs as soon as the 1st is open and there is nothing the reference.

Can I use the form times to halt all for a while before running the public
function
 
W

Wayne-I-M

Am doing something wrong here i think.

Say I have a form with a button and I want to open the form, then (after 10
seconds) change the capton of the button to "Chris MVP". Normally I would
use a really simple bit of code

Private Sub Form_Open(Cancel As Integer)
Me.TimerInterval = 10000
Me.ButtonName.Caption = "Chris MVP"
End Sub

But what is happening is that the capton is changing on open - not after 10
seconds.

Any ideas how to get the form to wait a while before running the code ?
 
A

Arvin Meyer [MVP]

I use the following function like:

Delay(2.5) ' 2 and a half seconds

Public Function Delay(dblInterval As Double)
'----------------------------------------------------
' Name: Delay
' Purpose: Generic delay code
' Inputs: dblInterval As Double
' Author: Arvin Meyer
' Date: January 2, 1999
' Comment:
'----------------------------------------------------
On Error GoTo Err_Delay
Dim Timer1 As Double
Dim Timer2 As Double

Timer1 = Timer()
Do Until Timer2 >= Timer1 + dblInterval
DoEvents
Timer2 = Timer()
Loop

Exit_Delay:
Exit Function

Err_Delay:
Select Case Err

Case Else
MsgBox Err.Description
Resume Exit_Delay
End Select

End Function
 
W

Wayne-I-M

Perfect - thank you Arvin


--
Wayne
Manchester, England.



Arvin Meyer said:
I use the following function like:

Delay(2.5) ' 2 and a half seconds

Public Function Delay(dblInterval As Double)
'----------------------------------------------------
' Name: Delay
' Purpose: Generic delay code
' Inputs: dblInterval As Double
' Author: Arvin Meyer
' Date: January 2, 1999
' Comment:
'----------------------------------------------------
On Error GoTo Err_Delay
Dim Timer1 As Double
Dim Timer2 As Double

Timer1 = Timer()
Do Until Timer2 >= Timer1 + dblInterval
DoEvents
Timer2 = Timer()
Loop

Exit_Delay:
Exit Function

Err_Delay:
Select Case Err

Case Else
MsgBox Err.Description
Resume Exit_Delay
End Select

End Function
 
K

Ken Snell \(MVP\)

I use this subroutine to go into a "holding pattern" -- it doesn't allow use
of exact seconds, but you can set the xlngLoopCounter number when you call
the subroutine to get the desired result:


' *****************************************
' ** Subroutine WasteTime **
' *****************************************

Public Sub WasteTime(Optional ByVal xlngLoopCounter As Long = 10)
Dim xlngLooping As Long
On Error Resume Next
For xlngLooping = 0 To xlngLoopCounter
DoEvents
Next xlngLooping
End Sub
 
Top