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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not allowing a Date/Time to be in the future 2

Status
Not open for further replies.

ImStuk

Technical User
Feb 20, 2003
62
US
I have a form that has a separate Date and Time field. Under the date field's Before_Update event I wrote some simple code to not allow a future date. My question is how can I make sure the Date and Time fields together are not in the future? Say the date is today, but it's not 1:00 PM yet...
 
Since a date/time field holds both date and time, I'd be inclined to recommend using only one field, then check against now().

I think one way of doing such check, could be something like this, given that the "time field" only contains time, not date.

[tt]if (dtMyTime > now - date) then
msgbox "oups - that's a bit into the future..."
end if[/tt]

Roy-Vidar
 
Why not simply this ?
If Me![Date field] + Me![Time field] > Now() Then
Cancel = True
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I will try that. The only reason I separate them is I have the date default set for Date() because most orders are the same day. And they need to be entered quickly, so I have input mask's for each field to let the user enter data fast. I've tried input mask's with the date/time field combined with very little success, but my experience with VB is limited.
 
Thank you. I didn't know it could work like that.
 
The reason "it works like that", is that a date/time field is to all intents and purposes a double. The integer part holds the date (as the number of days before or after 30/12/1899) and the fractional part holds the time as a fraction of the day (0.25 for example is 6:00 am, 0.5 is 12 noon etc). This means that you can add and subtract date and time values as you would any other number.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top