Highlight If time value is greater than the value stored in table (1 Viewer)

Ihk

Member
Local time
Today, 10:03
Joined
Apr 7, 2020
Messages
280
Hi I have been trying to highlight time value if it greater than the value stored in table.
But it does not work with ">" symbol.
But If I use "<>" then my code works, dont understand why not with ">"
I tried it from conditional formating and give it value from table or from a field to compare it does not work, but If I write the value itself (07:45:01) then it works.
But the same value is stored in table,
Table name = TimeSettings, Field is TimeIn (format: hh:nn:ss)

My vba code is here (on form load)
Code:
Dim CheckInTime As String
CheckInTime = TimeValue(DLookup("TimeIn", "TimeSettings"))
If CheckInTime > Me.txtTimeIn.Value Then
Me.txtTimeIn.BackColor = RGB(255, 0, 0)
End If
As I said above, this works only if I say not equal to "<>".

What is my mistake? Thank you
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:03
Joined
Oct 29, 2018
Messages
21,455
Can you post a sample db with test data instead?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:03
Joined
May 7, 2009
Messages
19,230
Code:
Dim CheckInTime As String
CheckInTime = TimeValue(DLookup("TimeIn", "TimeSettings"))
If CheckInTime > TimeValue(CDate(Me.txtTimeIn.Value)) Then
Me.txtTimeIn.BackColor = RGB(255, 0, 0)
End If
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:03
Joined
Sep 21, 2011
Messages
14,238
Why is checkintime a string?
 

Ihk

Member
Local time
Today, 10:03
Joined
Apr 7, 2020
Messages
280
Code:
Dim CheckInTime As String
CheckInTime = TimeValue(DLookup("TimeIn", "TimeSettings"))
If CheckInTime > TimeValue(CDate(Me.txtTimeIn.Value)) Then
Me.txtTimeIn.BackColor = RGB(255, 0, 0)
End If
Thank you very much. I made little correction of my own controls. But still marks the whole field (column red), rather only greater values.

Code:
Dim CheckInTime As String
CheckInTime = TimeValue(DLookup("TimeIn", "TimeSettings"))
If Me.txtTimeIn.Value > TimeValue(CDate(CheckInTime)) Then
Me.txtTimeIn.BackColor = RGB(255, 0, 0)
End If
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:03
Joined
May 7, 2009
Messages
19,230
what is your form, datasheet?
use conditional formatting.
 

Ihk

Member
Local time
Today, 10:03
Joined
Apr 7, 2020
Messages
280
what is your form, datasheet?
use conditional formatting.
Form is continuous.
In conditional formatting, I tried it works only If I put the real value in quotes eg "07:45:00" . But If give it path to my field in table, then it marks whole column red, irrespective of greater or smaller values.
But I dont want to fix the value under conditional formatting "07:45:00" , I want that the user should be be able to change the comparison value if some one want to compare it with different. And users will mess up, if they always to go to under conditional formatting to change.

Under vba, the above code does not work with either of greater > or Smaller < sign. But to test the code, I used the same code which works when I use not equal to sign <> . Why only not equal to sing works, but neither nor greater or smaller.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:03
Joined
May 7, 2009
Messages
19,230
you can Create a function and use the function in your Conditional Format Expression.
the sample is Split form but can be applied also in Continuous Form.
See Module1, see the Conditional Format on CheckInTime textbox.
 

Attachments

  • TimeConditional.accdb
    492 KB · Views: 323

bastanu

AWF VIP
Local time
Today, 01:03
Joined
Apr 13, 2010
Messages
1,402
Or use a dlookup in the conditional formatting instead of "give it path to my field in table"...
 

Users who are viewing this thread

Top Bottom