?
Solved

Validating a date using VBA code

Posted on 2007-12-05
2
Medium Priority
?
1,770 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 2000 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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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 specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Suggested Courses

762 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