Solved

Validating a date using VBA code

Posted on 2007-12-05
2
1,765 Views
Last Modified: 2013-12-05
I have a routine that reads in data from emails into the database using a SQL stored procedure.

One of these fields is DOB and everything is happy if the date is a valid one. It has just fallen over on a DOB that has been entered in the email as 13/14/1971 which is clearly not correct. As you would expect when this is passed to the stored procedure it falls over, so the validation needs to be done in the VBA before it is passed to the SP.

I wondered if anyone had an elegant way of checking that the date is a valid one (i can just ignore it if it isn't). Something like the way you would validate a field was numeric (i.e. IF myfield = val(myfield) ) would be great.

I can construct something longhand with loads of IF statements but this is very longwinded (for example it has to validate the day against the number of days in the month)

Thanks.
0
Comment
Question by:pauldonson
2 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 20410538
if isdate(fieldname) = true then
'whatever you do if it's ok
else
'do something else
end if
0
 

Author Comment

by:pauldonson
ID: 20410720
Fantastic, spot on. Thanks for the prompt response.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now