set date depending on current time (1 Viewer)

SDB

Registered User.
Local time
Today, 17:23
Joined
Sep 16, 2004
Messages
39
Hi All

I have a form that needs to have the date automatically entered depending on time, I have it set on form load and new record, so far I have this but if I change the time to test it doesn't work??

Private Sub Form_Load()
DoCmd.GoToRecord , , acNewRec
If Mytime <= 1500 Then
Me!PostDate = Date
Else
Me!PostDate = Date + 1
End If
End Sub

Private Sub Form_Timer()
Me.Mytime.Requery
End Sub

Private Sub Command4_Click()
On Error GoTo Err_Command4_Click


DoCmd.GoToRecord , , acNewRec
If Mytime <= 1500 Then
Me!PostDate = Date
Else
Me!PostDate = Date + 1
End If

Exit_Command4_Click:
Exit Sub

Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click

End Sub
 
Last edited:

RuralGuy

AWF VIP
Local time
Today, 10:23
Joined
Jul 2, 2005
Messages
13,826
So you simply want to use tomorrows date if it is after 3:00 in the afternoon? How do you set MyTime and what is it, a global variable?
 

SDB

Registered User.
Local time
Today, 17:23
Joined
Sep 16, 2004
Messages
39
So you simply want to use tomorrows date if it is after 3:00 in the afternoon?

yep, trying to work it out all day :confused:

[/QUOTE] How do you set MyTime and what is it, a global variable?[/QUOTE]
mytime is an unbound field which is set to look at the time constantly so that the postdate field is correct according to time/date
 

RuralGuy

AWF VIP
Local time
Today, 10:23
Joined
Jul 2, 2005
Messages
13,826
Why not change this:
If Mytime <= 1500 Then
to:
If Hour(Time) < 15 Then
 

SDB

Registered User.
Local time
Today, 17:23
Joined
Sep 16, 2004
Messages
39
That worked. Thank you very much. :)
 

RuralGuy

AWF VIP
Local time
Today, 10:23
Joined
Jul 2, 2005
Messages
13,826
That's great! If you want to include exactly 15:00 in the current date then you will want to change the logic slightly. Your previous code was <= 1500 and mine does not include 1500.
 

Users who are viewing this thread

Top Bottom