AfterUpdate Question

joe789

Registered User.
Local time
Today, 12:37
Joined
Mar 22, 2001
Messages
154
Hi Folks,

I am creating a database where a user enters data via a form, and depending on what value that user select from a certain drop-down box, different values become mandatory. I wrote a code which works perfectly as to alerting the user of requried required; however, how would I not only show a msgbox but also prevent the form from saving the record and advancing to a new record if not all the conditions are met? Is there some code I can use to mimic what happens if you enter perhaps a date in the wrong format, you get a message and must either correct that field before saving the record or cancel the entire record.

My code is below:

Private Sub Form_AfterUpdate()
If IsNull(Referral) And Performance_measure.Value = "Intake follow-up med/som" Then
MsgBox ("REFERRAL CANNOT BE NULL, PLEASE FIX!")
ElseIf Performance_measure.Value <> "Intake follow-up med/som" And ((IsNull(Date_of_discharge)) Or (IsNull(Date_of_followup_appointment)) Or (IsNull(Planned_followup)) Or (IsNull(Outcome_of_followup_appt))) Then
MsgBox ("Date of discharge, date of followup, planned followup, and outcomes fields are all required, please fix!")
Else
MsgBox ("OK")
End If
End Sub

The code works fine with prompting the user when their record is acceptable or when the record requires additional fields to be populated (but regardless, it saves the record and advances to the next new record) ... I do not want the user to bypass this, any help as to what line of code can be added to prevent the record from being updated if the record is not "OK" and wait until the user fixes the error before attempting to save the record again would be greatly appreciated.

Thank you very much,

Joe
 
Do you have a Save button on the form? If so then place your code on the Save button and not the After_Update event of the Form. Modify the code accordingly Setting focus back on the field(s) which are required or dont meet the criteria assigned.
For Example:
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
If Text0.value = "" Then
Msgbox "Text0 Cannot contain a Null Value"
Text0.Setfocus
Elseif Text1.value ="0" Then
Msgbox "0 is not acceptable, Refill"
Text1.Setfocus
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
End if
Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

Chris :cool:
 
Don't want user to bypass

Thanks Chris ... I tried that and it works perfectly but only if I use the save button. Is there a way to force the user to use the save button as oppossed to the user just hitting the 'tab' key which bypasses clicking on the save button and just saves the record and proceeds to a blank new record ... or if the user should save the record via clicking on the new record icon that is on the bottom of all the forms or just going thru the toolbar.

Thanks,

Joe
 
Turn off scroll bars, dividing lines, record selectors, navigation buttons by the properties setting of the form, put the same code on the Add Button. Put validations on each field in the lost_focus event or on the got_focus event of the next field which is to be filled in.
Chris
 
Last edited:

Users who are viewing this thread

Back
Top Bottom