Set Timer When an action is to occur.

mixedguy

Registered User.
Local time
Today, 02:06
Joined
Jun 12, 2002
Messages
52
Hi,

I'm trying to create in VB Code where a subform is set 'Visible' = False and at a specific time change that 'Visible' setting to True. Here is what I wrote but it doesn't seem to work. I've put this VB Code in the "On Open" Event Action of the main form.

Private Sub Form_Open(Cancel As Integer)
Dim MsgTime
MsgTime = Time
DoCmd.RunMacro "mcrUpdateNOC"
DoCmd.Maximize
If (MsgTime = #2:40:00 PM#) Then
Me!frmExitMsg.Visible = True
End If
End Sub

Thanks in advance!
 
mixedguy,

Your code will only work if someone opens the main form at
exactly 2:40:00 pm. You need to use the timer event on the
main form to repeatedly check if it is after 2:40, then you
should be all right.

hth,
Wayne
 
Still Doesn't Work

Hi Wayne,

This is what I tried and it still doesn't seem to work. I put the "Event Procedure" at the "On Timer" and I set the "Time Interval" at 3000.

Private Sub Form_Timer()
Dim MsgTime
MsgTime = Time
If (MsgTime = #4:05:00 PM#) Then
DoCmd.RunMacro "Macro1"
End If
End Sub

This doesn't run the Macro. Macro1 sets the Subform's Visible property to True.

Private Sub Form_Timer()
Dim MsgTime
MsgTime = Time
If (MsgTime = #4:05:00 PM#) Then
DoCmd.Beep
End If
End Sub

This code does work. My form makes a "Beep" sound when it reaches 4:05.

I don't understand why it won't run my macro epression.

Please help. Thanks in advance!

Todd
 
Yes I'm sure

Hi Wayne,

Yes I'm certain my form is open. I'll write the VB code and then save it in the Timer Event and set the Timer Interval at 3000. Then I'll open the Form in Form view and when it reaches the specified time I put in the VB Code it should execute whatever I tell it to do. The VB Code is able to execute when I use the "DoCmd.Beep" but it doesn't seem to wanna run my Macro. When I did "DoCmd.Quit" it was able to quit my application based on the Timer VB Code.

Hmm...I will look at it somemore on Monday Morning.
Thanks for all your help!

Todd
 
You code still must run at exactly 4:05:00. Instead, check for a range of time.

If (MsgTime => #4:04:30 PM#) And (MsgTime <= #4:05:30 PM#) Then
 
Worked.

Thanks, when I added the range to the code it executed my VB Code.

Todd
 
Typing into a text box in a form and letting it input it's values into the VBCode

One more Question. I'm trying to allow my supervisor to enter a time into a text box on a form the time he wants the pop up message box to appear on the screen.

This is my VB Code in the Timer Event:

Private Sub Form_Timer()
Dim MsgTime
MsgTime = Time
If (MsgTime >= "Forms![MainMenu]![Txt_Time]") And (MsgTime <= "Forms![MainMenu]![Txt_Time2]") Then
MsgBox "Please Exit 1st Alert Now so we may run our daily updates for 15 minutes", vbCritical, "Daily 1st Alert Updates"

End If
End Sub

The "Forms![MainMenu]![Txt_Time]" and "Forms![MainMenu]![Txt_Time2]" Format property is set to Long Time.

Ahhh if the value for [Txt_Time] is 2:05:00 PM and the value for [Txt_Time2] is 2:05:04 PM, the message box doesn't pop up. Can you please assist.

Thanks!
Todd
 
Try changing your timer interval to a smaller #
 

Users who are viewing this thread

Back
Top Bottom