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
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