A while ago now, June7 provided this code to me to allow users to update a table through a textbox, and then to update the listbox from which the record to update is selected.
Code:
CurrentDb.Execute "UPDATE tblSign_in SET TimeHelped=#" & Me.Txt69 & "# WHERE ID=" & Me.Lst60.Column(10)
This code works wonderfully. As time has passed, my db has evolved and I needed to add some reinforcement. I needed to force some common sense upon users. The following modified code forces users to update the record with a time in the "TimeHelped" field that occurs after the "Time_In" time.
Code:
If Me.Txt69 & "# WHERE ID=" & Me.Lst60.Column(10) > Me.Lst60.Column(6, Lst60.ListIndex + 1) Then
CurrentDb.Execute "UPDATE tblSign_in SET TimeHelped=#" & Me.Txt69 & "# WHERE ID=" & Me.Lst60.Column(10)
Else
MsgBox "Time Helped cannot be before Time In.", vbOKOnly
End If
Because time values are just serial numbers, the users must specify times using military format, to capture the correct time of day after 12:59 PM. Oddly though, Access doesn't recognize that any time between 13:00 and 13:59 are greater than 00:01 through 12:59. See for yourself in the attached sample db.
To verify my concern, open the db and then perform the following steps:
1. Enter a military time value within the 1300 hour
2. Click on Update
3. See error msg box appear
Now try steps one and two above with a military time after 13:59, and you'll see the time updated with what you put into the box.
My modified code will update using the 1300 hour only if the "Time_In" value is in the 1300 hour. I.E. if "Time_In" is 13:00, and you type in 13:01 into the box, the above code will update the record to show a "TimeHelped" value of 13:01.
Would anyone care to shed some light on this subject? I'd like to be able to use the 1300 hour.