Validating dates on forms

tpberks

New Member
Joined
Aug 16, 2011
Messages
3
Hi, I have been writing vba scripts for a few months now and the biggest headache I have come across, time after time, is how to validate a date input on a form. Nothing seems to work very well and I have tried lots of different suggestions from trawling through the 'net. There seems to be two main methods of formatting the date once it is input: CDate(Me.MyDate.Value) and FormatDateTime(Cells(r,c),vbShortDate). Which one is best and what is the difference between them?
When validating a dd/mm/yy date using IsDate(MyDate.Value), this ignores any date where the user has input dots instead of slashes and will also accept any input such as "1.234.45". I have tried Not MyDate.Value Like "##[/]##[/]####" which then forces me to input every character of the date i.e 01/03/2011.
Can someone please give me a definitive answer to the date input and validation issue? Many thanks.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
With "formitem_change" code you should be able to disable everything except numbers and slashes. That would give the appears of the period key or dash key simply not working.
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,882
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top