Conditional Field

G

Guest

I have a form for wich I would like the Shift to be set on one of the
controls, Day shift runs from 4:00 am to 3:30 pm and Swing Shift from 3:31 pm
to 3:00 am
I have this code but is not working and I do not know how to create a
diferent one,
I want the control text65 TO CHANGE TO day or Swing a soon as the time fits
its range, with out opening or closing the form.

Thank you for your help.

Private Sub Form_Timer()
Me.lblclock = Now()
If Time() > #4:00:00 AM# And Time < #3:30:00 PM# Then
Me.Text65 = "DAY"
Else
Me.Text65 = "SWING"
End If
End Sub
 
M

Marshall Barton

IT-1957 said:
I have a form for wich I would like the Shift to be set on one of the
controls, Day shift runs from 4:00 am to 3:30 pm and Swing Shift from 3:31 pm
to 3:00 am
I have this code but is not working and I do not know how to create a
diferent one,
I want the control text65 TO CHANGE TO day or Swing a soon as the time fits
its range, with out opening or closing the form.

Thank you for your help.

Private Sub Form_Timer()
Me.lblclock = Now()
If Time() > #4:00:00 AM# And Time < #3:30:00 PM# Then
Me.Text65 = "DAY"
Else
Me.Text65 = "SWING"
End If
End Sub


That looks like it should work if the form is already open
and you set the form's TimerInterval property to around one
minute (60000).

You can use the same code or just call that procedure from
the form's Load event to set the value to cover the first
partial minute when the form is opened.
 
G

Guest

It works when I open the form, but if the time is 3:30 pm and then it changes
to 3:31 pm the field Text65 should change to "SWING" but it doesn't until i
close and reopen the form. Is there a way to update this control with the
form alwasy open?
 
D

Douglas J. Steele

To what did you set the form's TimerInterval property? As Marsh suggested,
setting it to 60000 means that your form should update itself every minute.
 
G

Guest

Thanks for your help, I had the time interval set at 1000, I have changed it
to 60000, but I get "SWING" even whe it is befor 3:30 pm (3:25 pm) so I
assume there is and erro on the first part of the code:

If Time() > #4:00:00 AM# And Time < #3:30:00 PM# Then
 
D

Douglas J. Steele

I would think that should work, but just in case, try:

If Time() > TimeSerial(4,0,0) And _
Time() < TimeSerial(15,30,0) Then

Me.Text65 = "DAY"
 
G

Guest

Thanks,
It is still giving me "SWING"

Looks like the time( ) function is not being recognized.
 
D

Douglas J. Steele

Put in a simple

MsgBox Time()

and see what it returns.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


IT-1957 said:
Thanks,
It is still giving me "SWING"

Looks like the time( ) function is not being recognized.
 
G

Guest

Thanks for your help, after trying many times and stiil not getting the
result, I have tried a diferent appoach, the code works well on a control but
not on bv, i have set the data to update the shift on one query, the shift is
not showing on the form because i coundn't get it to chance with the clock.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top