code check please? (1 Viewer)

QMDirk

Member
Local time
Today, 00:05
Joined
Nov 16, 2019
Messages
52
I want a User to click in a text box. Upon clicking, the current time appears AND I want the "Shift" textbox to auto-populate with either a 1 or a 2. I used CDbl to convert the the system time to a decimal, then made it a math problem. Midnight is 0.0, 6am is 0.25. 1st shift starts at 0.25. 2nd shift runs until 3am which is 0.125, but sometimes runs up until 6am. 1st shift ends at 5pm, 0.7083. So anytime between .25 and .7083 should show a 1 but before 6am and after 5pm, it should show a 2. Except it isn't changing the Shift to a 2 and the time right now is (CDbl = 0.841666666....does the code look correct? anyone? thanks.


Private Sub Start_Time_Click() 'enter the time by clicking the text field.
Me.Start_Time.Value = Format(Now, "HH:MM")
If Me.t.Value < 0.25 And Me.t.Value > 0.7083 Then
Me.Shift.Value = 2
Else
Me.Shift.Value = 1
End If
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:05
Joined
May 7, 2009
Messages
19,232
If Me.t.Value >= 0.25 And Me.t.Value <= 0.7083 Then
Me.Shift.Value = 1
Else
Me.Shift.Value = 2
End If

//edited.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:05
Joined
Oct 29, 2018
Messages
21,454
Hi. I think maybe the problem is the use of the Format() function, because it converts the time into text.
 

QMDirk

Member
Local time
Today, 00:05
Joined
Nov 16, 2019
Messages
52
Hi. I think maybe the problem is the use of the Format() function, because it converts the time into text.
there's a hidden text box on the form named "T" which is set to me.T.value = (CDbl(Time)). That's the value that is used in the comparison. But thanks, the previous suggestion actually worked.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:05
Joined
Oct 29, 2018
Messages
21,454
there's a hidden text box on the form named "T" which is set to me.T.value = (CDbl(Time)). That's the value that is used in the comparison. But thanks, the previous suggestion actually worked.
Cool. Glad to hear you got it sorted out. Cheers!
 

Users who are viewing this thread

Top Bottom