I have a form with multiple subforms arranged as tabs. The tab I am concerned with here contains information about individuals such as name, age and other demographics. There is a subform on this tab that contains phone numbers and the phone type. The main form is named Client_Intake_form, The subform on the tab is called persons_subform, and the phone number subform is called phone_contact_subform. The subform has a text box on it for the phone number named 'phoneNm' and a combo box for the phone type named 'CmboPhoneType'. Users don't have to enter phone numbers for people but if they enter a phone number, they have to enter a phone type or Access generates an error. The error is " The Microsoft Access databse engine cannot find a record in the table 'tblPhoneTypes' with key matching field(s) 'phonetype_ID'" I don't want the user to see this error so I have tried to create code to show my own error. However, after my error message is shown, the Access error still pops up. Is there any way to stop this behavior? I have tried putting this code in a variety of events on the form including the forms before update event and on the text box itself such but have failed to stop the Access error.
Here is the code, currently on the before update event for the text box on the phone contact subform:
Code:
Private Sub PhoneNm_BeforeUpdate(Cancel As Integer)On Error GoTo Err_PhoneNm_BeforeUpdate
If Me.NewRecord = True And Me.CmboPhoneType = 0 Then
Msgbox " You must enter the type of phone.", vbOKOnly, "Missing info."
Me.CmboPhoneType.SetFocus
End If
Exit_Err_PhoneNm_BeforeUpdate:
Exit Sub
Err_PhoneNm_BeforeUpdate:
Msgbox Err.Description
Resume Exit_Err_PhoneNm_BeforeUpdate
End Sub
Here are the table relationships:
Any advice would be appreciated.