Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to pause 3 seconds before closing application? 2

Status
Not open for further replies.

AAAccess

Technical User
Dec 5, 2003
24
US
Is there a way to program a button to pause for 3 seconds before closing the application using VB?
 
Hi AAAccess,

First create a command button that will display "Close Form" or something like that to the user, lets call it cbCloseForm. Then place the following code in the On_CLick event for the cbCloseForm button:


Private Sub cbCloseForm_Click()
Me.TimerInterval = 3000
End Sub


This will set your timer to 3 seconds (timer interval is set in milliseconds, hence 3000 = 3 seconds)

Then for your Forms "On Timer" event procedure place the code that you would normally use for your close button:


Private Sub Form_Timer()
On Error GoTo Err_Command1_Click


DoCmd.Close

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click
End Sub


This will pause for 3 seconds before closing the form. To adjust the time simply change the number (in milliseconds) in the cbCloseForm_Click() event procedure.

Let me know if this helps.

Regards,
gkprogrammer
 
Hello Again,

I just noticed that you wanted to close the App. and not just a form. In this case you would place this code in the Form_Timer procedure instead:


Private Sub Form_Timer()
On Error GoTo Err_Command1_Click


DoCmd.Quit

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click
End Sub


Regards,
gkprogrammer
 
Yes, thank you both, I do want to close the application. And this works perfectly!! Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top