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

Why is this so hard?

Status
Not open for further replies.

dominicgingras

Technical User
Jul 15, 2002
53
CA
I have a post somewhere related to that but this time I will try to refine my question.

I need to enter a full date in a field called "shippingtime".

How can I make sure that my user are entering a date and the time. My user are pesky one. I dont want to use an input mask because its will to difficult to enter the proper information fast.
 
I guess you will have to decide between "fast" and "proper".
The right choice would be "proper" (IMO).
Check the field in the BeforeUpdate event of the form:

If Not IsDate(Nz(DateTimeBox,"Nothing")) Then
MsgBox "Date and time are required, dude!"
Cancel = True
End If

and your user will curse you everytime he forgets to comply...

Good luck

[pipe]
Daniel Vlas
Systems Consultant
 
That will just make sure that he has enter a date but he could enter a date without a time ex: 12-03-2003. I need this format: 12/02/2003 11:00:00 PM. Tell me what you think!
 
When you enter a date (but not the time) in a field, the time is stored as 00:00:00

You could check for another time:

If Format(DateField, "hh:nn:ss")="00:00:00" then
MsgBox "Ooooops, what time is it?"
End If

HTH

[pipe]
Daniel Vlas
Systems Consultant
 
Hi,

The easiest way would be to set the shipping time like this:

Me!shippingtime = Now()
Then it will display in this format:
3/13/2003 1:44:04 AM

You can have this set by setting the code on shippingtime's "On Click" event - then the user would only have to click on the text box to input the shipping time.
That way you don't have to worry about what the user types in because it will automatically be filled in for you.

HTH,

jbehrne If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Nope...the easiest way would be to set the a Default value of the field to Now()...no click needed...but...what about later data entry...or shipments scheduled in the future?

Just a thought.


[pipe]
Daniel Vlas
Systems Consultant
 
The shipping date is never now() anyway. The bottom line to this is that a user can enter any kind of date in access and their is no way to make sure that he took the time to enter the time. I will try some of danvlas option.
 
I tried this litte piece of code and I have put it in the before update. I need to to the oposite so if my user only enter the time he gets a message. I tried to lookup in the help but its kind of confusing.

Thank


If Format(HeureDépart, "dd/mm/yy") = "00/00/00" Then
MsgBox "Not a date only a time"
End If

 
Is the shipping time always a future time??? If so you can evaluate the validity of the date, maybe you can use:

If Format(HeureDépart, &quot;dd/mm/yy hh:nn:ss&quot;) < Now() Or Format(DateField, &quot;hh:nn:ss&quot;)=&quot;00:00:00&quot; Then
MsgBox &quot;Not a date only a time&quot;
End If

This will check the entered time against the now time and date...if the entered time/date is missing the date, the value will be less and your error applies...The section after the Or statement checks to make sure a time was entered....I did not test this myself, but it should work. Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCSA, CNA, MCP, Network+, A+
w: robert.l.johnson.iii@citigroup.com
h: mstrmage@tampabay.rr.com
 
OK here's a last ditch effort:

Access dates are really floating point numbers. The integer part is the number of days since 30-Dec-1899 00:00:00, which you can find out by using this statement:

debug.print format(0, &quot;DD-MMM-YYYY HH:NN:SS&quot;)

to get 12 noon, try this:

debug.print format(.5, &quot;DD-MMM-YYYY HH:NN:SS&quot;)

to find out if a date has no time, just say

Function HasDate(InputDate As Date) As Boolean
HasDate = (Fix(Abs(InputDate)) > 0)
End Function

Function HasTime(InputDate As Date) As Boolean
HasTime = (InputDate <> Fix(InputDate))
End Function

Sub EvalDate(InputDate As Date)
Debug.Print Format(InputDate, &quot;DD-MMM-YYYY HH:NN:SS&quot;) & &quot; Has Date: &quot; & HasDate(InputDate) & &quot;, Has Time: &quot; & HasTime(InputDate)
End Sub

Sub TestDates()
EvalDate #1/1/2000#
EvalDate #12:00:00 PM#
EvalDate #1/1/2000 12:00:00 PM#
EvalDate #1/1/2000 12:00:00 AM#
End Sub

so it works great for every time except midnight, and every date except 30-dec-1899.

If this is unacceptable, you have to do some text processing.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top