Countdown timer (1 Viewer)

vexatu

Registered User.
Local time
Today, 06:06
Joined
Mar 2, 2009
Messages
11
Hello,

I want to make a form, with a countdown timer then close itself. Let's say that when I opened the form, a countdown timer displays the number of "n" seconds/minutes left until the form will close, and after "n" second/min the form closes. Could anyone help me step by step, please ?
 

RuralGuy

AWF VIP
Local time
Today, 07:06
Joined
Jul 2, 2005
Messages
13,826
Hmmm...not ghudson's usual standard. Most of the links here have a countdown form that you can use. Post back if you need more assistance.
 

missinglinq

AWF VIP
Local time
Today, 09:06
Joined
Jun 20, 2003
Messages
6,423
Create a Label on your form and name it TimeLeft.

Copy and paste this code into the code window for the form
Code:
Public Loops As Integer

Private Sub Form_Load()
 Me.TimerInterval = 1000
 Form_Timer
End Sub

Private Sub Form_Timer()

Static StartTime As Date

Dim SecondsToCount As Integer

SecondsToCount = 15 'Set this variable to the total number of seconds to count down

If Loops = 0 Then StartTime = Time
 
 Min = (SecondsToCount - DateDiff("s", StartTime, Time)) \ 60
 Sec = (SecondsToCount - DateDiff("s", StartTime, Time)) Mod 60
 Me.TimeLeft.Caption = "Form will close in " & Min & ":" & Format(Sec, "00")
 Loops = Loops + 1

 If Me.TimeLeft.Caption = "Form will close in 0:00" Then
   DoCmd.Close acForm, Me.Name
 End If

End Sub

Replacing the 15 in the line

SecondsToCount = 15

with the total numbe rof seconds you watn the countdown to last.
 

Users who are viewing this thread

Top Bottom