Solved

Validating a date using VBA code

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 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