473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 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 22670
-----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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
by: phil_gg04 | last post by:
Dear Javascript Experts, Opera seems to have different ideas about the visibility of Javascript functions than other browsers. For example, if I have this code: if (1==2) { function...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
2
by: sushil | last post by:
+1 #include<stdio.h> +2 #include <stdlib.h> +3 typedef struct +4 { +5 unsigned int PID; +6 unsigned int CID; +7 } T_ID; +8 +9 typedef unsigned int (*T_HANDLER)(void); +10
8
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
4
by: alex | last post by:
I am so confused with these three concept,who can explained it?thanks so much? e.g. var f= new Function("x", "y", "return x * y"); function f(x,y){ return x*y } var f=function(x,y){
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.