Date validation teaser!!!

adambc

Active Member
Joined
Jan 13, 2020
Messages
370
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I have a Workbook which records requests received, which is periodically updated with progress - NB it is not used in lieu of Project Management/Project Tracking tools; it is there to provide the Executive Team in the charity I’m volunteering at (in retirement!) an oversight …

It works using two UserForms …

frmNewRequest … used to add new requests - there are a number of Command Button/Text Box combinations where the Command Button calls a Date Picker and writes the date selected to the Text Box - behind this I have written a simple VBA date validation routine that is triggered by a Text Box Change to ensure that the date selected is not before today

frmUpdateRequest … is essentially the same form except that it loads the data into the form from the underlying Worksheet record - I still need the aforementioned Command Button/Text Box combinations including the validation, but the problem occurs when a date previously entered has now past - when the form loads the data (into the Text Box), the validation kicks in, which I don’t want to happen to allow reporting on dates “missed”

Can anyone help eg is there a way I can distinguish between a Text Box Change as a result of the Command Button/Date Picker, from a Text Box Change as a result of loading an existing record?

Thanks for any help you can give me …
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Don't use the Change event? Not sure what would be more suitable for your use re date validation but I suspect BeforeUpdate. Consider doubleclick event on date fields and eliminate the buttons?
 
Upvote 0
Don't use the Change event? Not sure what would be more suitable for your use re date validation but I suspect BeforeUpdate. Consider doubleclick event on date fields and eliminate the buttons?
@Micron

How will BeforeUpdate help? Surely the validation will still trap updates as a result of loading data rather than “manual” input?

And how would a doubleclick event vs. a Command Button help?
 
Upvote 0
I have a Workbook which records requests received, which is periodically updated with progress - NB it is not used in lieu of Project Management/Project Tracking tools; it is there to provide the Executive Team in the charity I’m volunteering at (in retirement!) an oversight …

It works using two UserForms …

frmNewRequest … used to add new requests - there are a number of Command Button/Text Box combinations where the Command Button calls a Date Picker and writes the date selected to the Text Box - behind this I have written a simple VBA date validation routine that is triggered by a Text Box Change to ensure that the date selected is not before today

frmUpdateRequest … is essentially the same form except that it loads the data into the form from the underlying Worksheet record - I still need the aforementioned Command Button/Text Box combinations including the validation, but the problem occurs when a date previously entered has now past - when the form loads the data (into the Text Box), the validation kicks in, which I don’t want to happen to allow reporting on dates “missed”

Can anyone help eg is there a way I can distinguish between a Text Box Change as a result of the Command Button/Date Picker, from a Text Box Change as a result of loading an existing record?

Thanks for any help you can give me …
I have solved the teaser myself!!!

I’ve put the validation in the Command Button sub before the date selected gets anywhere near the Text Box - as a result, when I load a date in the past into the Text Box no validation takes place …

Simple when you think about it!!!
 
Upvote 0
Solution
How will BeforeUpdate help? Surely the validation will still trap updates as a result of loading data rather than “manual” input?
If data doesn't pass validation, you cancel the event - no update, but that's about validation. Your problem was that the change event was being triggered by the userform initialization event, yes? You solved your problem the same way - you just moved validation to a button click event. Usually, validation is done before the data is accepted in the control, not after.
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

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