Validating a date using VBA code
Posted on 2007-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)