I have an unbound textbox txtDateofIncidentRecorded
which gets its value directly from a date picker. When a date is selected a subroutine txtdateSelected decides which controls should be visible based on the date selected.
I would like to check whether the chosen date is in the future (this makes no sense to the form in general) and if so informs the user and return the date in the textbox to the current default date (today)
Something tells me the before_update event might be the solution but I cant get it to do what I want.
I tried this as a fifth attempt!!!
Code:
Private Sub txtDateofIncidentRecorded_BeforeUpdate(Cancel As Integer)
If Me.txtDateofIncidentRecorded > Date() Then
me.txtdateofIncidentRecorded = date()
MsgBox "Date selected cannot be in the future tense. Date will be reset to today."
Cancel = True
End If
txtdateSelected 'a subroutine which decides which details should be visible based upon the selected date
End Sub
I get an error saying
runtime error 2115 - The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Microsoft Office Access from saving the data in the field.
VBA has stopped at
The first line in the subroutine txtdateSelected
Hoping someone out there can advise me.