472,096 Members | 2,286 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,096 software developers and data experts.

IsTime() function?

Is there an easy way to validate with VBA that a user entered a time value
into a text box? I didn't see anything in the validation options on the text
box properties.

Steve

Nov 12 '05 #1
8 22365
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In debug window:

? IsDate("06:30")
True

Dates & Times are stored as DateTime data types, hence the use of
IsDate().

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQJhr2IechKqOuFEgEQIZ3ACg0Xc5SzjbEpmdkeS+1PEInh TLTT8AnRIi
dVyzkr9uOkMLP9LZKpYNExVM
=H/pj
-----END PGP SIGNATURE-----
Steve Leferve wrote:
Is there an easy way to validate with VBA that a user entered a time value
into a text box? I didn't see anything in the validation options on the text
box properties.


Nov 12 '05 #2
You can use the IsDate function but please be warned the Isdate function is
very generous in what it considers to be a date.

--
Terry Kreft
MVP Microsoft Access
"Steve Leferve" <le********@osu.edu> wrote in message
news:c7**********@charm.magnus.acs.ohio-state.edu...
Is there an easy way to validate with VBA that a user entered a time value
into a text box? I didn't see anything in the validation options on the text box properties.

Steve

Nov 12 '05 #3
Terry Kreft wrote:
You can use the IsDate function but please be warned the Isdate function is
very generous in what it considers to be a date.


Dates have always been a problem in Access:

?isdate("01/13/2004")
True

Should not be true for the UK but it is. A lot of errors can go
unchecked like this.

--
Error reading sig - A)bort R)etry I)nfluence with large hammer
Nov 12 '05 #4
Trevor Best <nospam@localhost> wrote in
news:40***********************@auth.uk.news.easyne t.net:
Terry Kreft wrote:
You can use the IsDate function but please be warned the Isdate
function is very generous in what it considers to be a date.


Dates have always been a problem in Access:

?isdate("01/13/2004")
True

Should not be true for the UK but it is. A lot of errors can go
unchecked like this.


Pilot error. You have to pass unambigous data to it for it to give
you reliable answers.

?IsDate("2004/13/01")
False

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #5
I have never had problems as you are referring too. But, I would tie the
form to a table. Define the date/time field as a date format.
--
Dean Covey
www.coveyaccounting.com

MS-Office Certified:
http://www.microsoft.com/learning/mc...st/default.asp

"Steve Leferve" <le********@osu.edu> wrote in message
news:c7**********@charm.magnus.acs.ohio-state.edu...
Is there an easy way to validate with VBA that a user entered a time value
into a text box? I didn't see anything in the validation options on the text box properties.

Steve

Nov 12 '05 #6

In order to pass unambiguous data you would have to validate the data first,
hence the Isdate function is not suitable for validating user input.

It's perfectly possible for a user to enter "01/13/2004" and if you rely on
the Isdate function to validate then in a ddmmyy culture you'll get a false
positive.

--
Terry Kreft
MVP Microsoft Access
"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@24.168.1 28.86...
Trevor Best <nospam@localhost> wrote in
news:40***********************@auth.uk.news.easyne t.net:
Terry Kreft wrote:
You can use the IsDate function but please be warned the Isdate
function is very generous in what it considers to be a date.


Dates have always been a problem in Access:

?isdate("01/13/2004")
True

Should not be true for the UK but it is. A lot of errors can go
unchecked like this.


Pilot error. You have to pass unambigous data to it for it to give
you reliable answers.

?IsDate("2004/13/01")
False

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc

Nov 12 '05 #7
> Is there an easy way to validate with VBA that a user entered a time value
into a text box? I didn't see anything in the validation options on the text
box properties.

Steve


The function below will validate whether they've entered a time value.
Note that it doesn't accept date/time values that include the date
part. So check out the results:

---
?istime(null)
False
?istime("test")
False
?istime("5/5")False
False
?istime("2/2 12 p")
False
?istime("12 p")
True
---
'---
Public Function IsTime(dat As Variant) As Boolean
'handle null values
If IsNull(dat) Then
IsTime = False
'handle text-values, or values that would otherwise not convert to
a date
ElseIf Not IsDate(dat) Then
IsTime = False
'handle valid 'date' values, but ensure the date part of the
date/time value
'has not been entered. We only want the 'time' part of the
date/time value.
ElseIf Fix(CDbl(CDate(dat))) <> 0# Then
IsTime = False
'ok, so it's a valid date, and it is between 0 and 24 hours, i.e.
it's a time value.
Else
IsTime = True
End If
End Function
'---

Enjoy,
Pete
Nov 12 '05 #8
Pete wrote:
Is there an easy way to validate with VBA that a user entered a time value
into a text box? I didn't see anything in the validation options on the text
box properties.

Steve

The function below will validate whether they've entered a time value.
Note that it doesn't accept date/time values that include the date
part. So check out the results:

---
?istime(null)
False
?istime("test")
False
?istime("5/5")False
False
?istime("2/2 12 p")
False
?istime("12 p")
True
---


?IsTime("Hair past freckle")

Well, I forgot my watch today! :-)

--
Error reading sig - A)bort R)etry I)nfluence with large hammer
Nov 12 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by domeceo | last post: by
5 posts views Thread by phil_gg04 | last post: by
2 posts views Thread by laredotornado | last post: by
2 posts views Thread by sushil | last post: by
8 posts views Thread by Olov Johansson | last post: by
3 posts views Thread by Beta What | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.