Enhancement to my Code to Check if a Date is Greater Than the Current Date
I have code that checks a date in a field to see if it is less than or equal to the current date. I have it on the BeforeUpdate Event of the Field, so the focus automatically goes back to this field, but the old date that the user entered is still sitting there.
After the cursor's focus is back in that field, I would like to have the field wipe out the old date (clear the field) and be blank and ready for the user to enter the correct date.
When I tried putting in the following line of code: me.Quality_Review_Date.value = ""
after the line of code "Cancel=True", I get run-time error '2115'.
Below is the code I'm using to check the Date field:
If Me.Quality_Review_Date.Value > (Date) Then MsgBox ("You must enter a date less than or equal to today's date!") Cancel = TrueEnd If
If Me!Quality_Review_Date.Value > Date Then MsgBox ("Please enter a date less than or equal to today's date.") Me!Quality_Review_Date.Undo Cancel = TrueEnd If
Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.
Sorry, I didn't see in your posting that you had put in the "Undo" command. I pasted in your code from ID: 39261706, and it worked. It places the cursor back in the Date field, with the date highlighted, the only thing is it doesn't wipe out the date that is already there.
Is there a way around this to have the field get wiped out all together? If not, that's fine. At least the field/date is highlighted and the user can just type and it will wipe out the existing date with the new date the user types in.
And no, Undo will not wipe out anything, just revert a change.
If that isn't enough, you will have to use the AfterUpdate event but this will, of course, only trig if data has been changed, and that is what you wish to prevent.
And if you put the line before Cancel = True
Regards