Solved

Validating a date using VBA code

Posted on 2007-12-05
2
1,764 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

744 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

11 Experts available now in Live!

Get 1:1 Help Now