Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with checking time 2

Status
Not open for further replies.

load3d

Programmer
Feb 27, 2008
117
US
The purpose of this form that I'm having trouble with is to create an appointment. The objective of what I am trying to do now is check the entered time against the actual time so that I can prevent appointments being created the occur in the past.

On my form I have 3 drop down boxes (1 for hours, 1 for minutes and 1 for AM/PM)

At the end of the form I am combining the 3 fields and adding a record to the appointment table

My code for that is:

AppointmentTIME = Me.hours & ":" & me.mins & " " & me.tod

then I'm taking that number and I have tried various procedures for example

IF LEFT(Me.HOURS, 2) < LEFT(TIME(), 2) then msgbox = "you cannot create appointments that occur in the past"

I have tried a bunch of different variations stemming from this concept and I cannot get it to work. I think I have my hours, minutes and time of day fields as text fields does that matter? Do I need to convert me.AppointmentTIME to a time field before I can check it against TIME()?



 
Another way:
Dim AppointmentTIME As Date
AppointmentTIME = TimeSerial(Me!hours, Me!mins, Me!tod)
If AppointmentTIME < Time Then MsgBox = "you cannot create appointments that occur in the past"



Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That worked


Dim time1 As Date
Dim time2 As Date

Me.AppointmentTime = Me.Hours & ":" & Me.Mins & " " & Me.Tod


If Me.Mins = "0" Then Me.Mins = "00"
If Me.Mins = "5" Then Me.Mins = "05"

time1 = CDate(Me.AppointmentTime)
time2 = Time()


ElseIf time1 < time2 Then errmsg402 = MsgBox("You cannot create appointments that occur in the past!", vbOKOnly, "Invalid Appointment Time!")
Me.Hours.SetFocus

-------------------------------------




 
What would be the best way do you think to get around appointments being created for after midnight?

For example: It's 11:30 PM and I want to create an appointment for 12:05 AM the check the I have put together would prevent that because it will think that that time has already passed?

Do you think that the best thing to do would be to create module that bypasses the check if time() is greater than #11:00:00 PM#?

It will be hard to test this.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top