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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code Not Working

Status
Not open for further replies.

xmeb

Technical User
Jun 5, 2013
89
0
0
I am trying to make the following code work but so far it does nothing. What's wrong with it?

Code:
Private Sub Form_Timer()
    
Clock.Caption = Time        ' Update time display.
    
If Weekday(Date) = 3 And Time() >= #9:00:00 AM# Then

Me.Visible = True

End If

End Sub
 
What event is triggering this sub routine? Are you trying to make a form appear at a certain time?
 
hi,

Did you try putting a break in the code in the first statement to step thru and see what's happening?

faq707-4594

You can answer many of your own questions this way.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Yes, or a macro message box. Thanks.
 
I do not know how to put a break in the code. Thanks.
 
I have a feeling that you don't have any event calling the subroutine. Even though the subroutine is going to open a msgbox at a certain, something needs to trigger the subroutine to even check what time it is. Try putting this piece of code in the "OnCurrent" event of a form. Or on a button click for faster testing.
 
I put the following code in a button but when I click the button nothing happens.

Code:
Private Sub Command6_Click()
    
If Weekday(Date) = 3 And Time() >= #9:00:00 AM# Then

Me.Visible = True

End If

End Sub

Is there better code to make this work?

Thanks!
 
What is "Me"? I think it is the form the button is on. Therefore it is already visible. Replace the line: 'Me.Visible = True' with "MsgBox Time()". Let me know what happens.
 
Message box appears with the current time displayed.
 
Cool so your code is fine I just think you are trying to make the wrong thing visible. "Clock.Caption = Time" I think this means you have a Label control named 'Clock' that you want to make visible. So instead of 'Me.Visible' try 'Me.Clock.Visible'
 
This line simply makes the current form visible. If the button Command6 is visible then the form is already visible so the code is not going to change anything.

Code:
Me.Visible = True

What do you want to make visible?


Duane
Hook'D on Access
MS Access MVP
 
I guess I got it all messed up as usual. When the time is reached I want a macro message box to appear. Thanks.
 
I think you need to set the Timer Interval to something other than 0 and then add some code to the On Timer property event. You might want to update Timer Interval to 0 once the message has popped up so it doesn't pop up and pop up and pop up and pop up.

Duane
Hook'D on Access
MS Access MVP
 
I have the following code working. I could put it on my "Save" button on the form which would (I think) trigger it. If I do that is there a way for older ones to be "dismissed" or otherwise done away with?

Code:
Private Sub Command6_Click()
    
If Time() >= #4:06:00 PM# Then

MsgBox "It is time to..."

End If

If Time() >= #4:15:00 PM# Then

MsgBox "Now it is time to..."

End If

End Sub
 
Timer Interval is set to 1000.
 
Using the Timer event, you set the interval to 0. Without that, you could set some other property or value and then check it when the button is clicked.

It would help if you explained the context of what you are attempting to do (big picture).

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top