By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,504 Members | 2,606 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,504 IT Pros & Developers. It's quick & easy.

IsTime() function?

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
-----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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
> 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

P: n/a
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.