MsgBox to display using Timer event

jpkeller55

New member
Local time
Yesterday, 20:14
Joined
May 10, 2012
Messages
9
I have a form (MS Access 2003) that has a button that when pressed, assigns the current time to field [Time1] using
Code:
Me.Time1 = Now()
I have another field [Time2] that adds 15 minutes to [Time1] using the following in the Control Source field
Code:
=DateAdd("n",15,[Time1])
I was wanting to use these to force a message box when the system time reached Time2 and tried the following code on the Form ON TIMER event (Interval at 1000 ms) but it does not work.
Code:
If Time() > Me.Time2 then
MSGBox "Time to show message"
End if

I tried putting in a manual time in the VBA such as:
Code:
If Time() > #2:05:00 PM#
MSGBox "Time to show message"
End if
which worked. So, I am guessing there is something with my orignal code using Me.Time2 that is causing the problem. Any ideas?
 
For starters, you've used Now() to populate the textbox, which includes the date. Then you test using Time(), which does not, so you have an apples to oranges comparison.
 
OK, that was the problem. When I changed the code to make Me.Time1 = Time() it worked. I also amended the code so that I did not need 2 time text boxes. So my code looks like:

On the click event of the button:
Code:
Me.Time1 = DateAdd("n", 15, Time())
which establishes the time for the msg box to show in 15 minutes.

On the Timer event of the form, the code is:
Code:
If Time() > Me.Time1 Then
MsgBox "Time to show message"
End if

Thanks for setting me straight.
 

Users who are viewing this thread

Back
Top Bottom