UNdo if date is null (1 Viewer)

theinviter

Registered User.
Local time
Today, 06:16
Joined
Aug 14, 2014
Messages
237
Dear Guys;
i need a help.

i have a form to filter to fill , if user did not select date first and he add any value them , i want msgbox to show text message and cancel the data entered;

i tried this but not working.

Private Sub TOTAL_PHYSICAL_COUNT_AfterUpdate()

If IsNull(Date_From) Then
MsgBox " Please Add Date Range"
Me.TOTAL_PHYSICAL_COUNT.Undo

Else

TRT= Text140
End If
End Sub
 

June7

AWF VIP
Local time
Today, 05:16
Joined
Mar 9, 2014
Messages
5,423
Are these UNBOUND controls just for input of filter criteria?

If these are BOUND controls for input of data to record, use form BeforeUpdate event for data validation of record.
 

theinviter

Registered User.
Local time
Today, 06:16
Joined
Aug 14, 2014
Messages
237
Are these UNBOUND controls just for input of filter criteria?

If these are BOUND controls for input of data to record, use form BeforeUpdate event for data validation of record.
yes its bound to record in data. but i tried before update , the same problem , if i type any number and date field in null it will be added to record.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 09:16
Joined
Feb 19, 2002
Messages
42,970
If you want to prevent data from being saved, you need to use the FORM's BeforeUpdate event AND you MUST cancel the event. Read through the help entry June posted. You cannot use the control level events to check for null, even if you use the correct event. WHY? Because these control events do not fire unless the control obtains the focus and is changed in the case of the BeforeUpdate event. You must use the form's BeforeUpdate event to ensure that all data is present. You could use the control's BeforeUpdate event for other types of validation but if the validation involved multiple fields. For example if endDate must be >= StartDate, then you would need to use the FORM's before update event. Using the control events would be too complicated since both fields can't be entered at the same time so you can end up with null in at least one control. Personally, I do ALL my validation in the Form's BeforeUpdate event so it is all together. the only time I use the control's BeforeUpdate event is if I am making sure that some ID like SSN has not already been entered. If I am not going to let the user save the record with a missing or duplicate SSN, then why let him fill in all the controls before I tell him there is a problem.

Just undoing seems a bit Draconian. Might it not be better to cancel the update but allow the user to try again?
 

Users who are viewing this thread

Top Bottom