So I have a form for entering a new client to our database. The table (tblClient) is connected (1tomany) to tblHouseholds. The field in the form for adding to households is a combo box. When closing the form if data has been entered and nothing has been entered in the households field an error shows up: "The Microsoft acces database engine cannot find a record in the table 'Households' with key matching field(s)'HouseholdID'". I know why this shows up, I need help handling the error since the field is required. The household field is the first field when the form is opened so my thought was to add the following code to the lost focus event:
Private Sub Combo293_LostFocus()
If IsNull(Combo293) Then
MsgBox ("Household Field Required")
Combo293.SetFocus
End If
End Sub
This works just the way I want. The problem is if the user opens the form and doesn't enter any data and just tries to close the form, the msgbox shows up a bunch of times and the user has to exit out 2 or 3 times before the form closes. How do I get the onclose function to ignore the lost focus. I tried using the beforeupdate and onerror events but there was too much code and I was getting lost. Any help is appreciated!!
Private Sub Combo293_LostFocus()
If IsNull(Combo293) Then
MsgBox ("Household Field Required")
Combo293.SetFocus
End If
End Sub
This works just the way I want. The problem is if the user opens the form and doesn't enter any data and just tries to close the form, the msgbox shows up a bunch of times and the user has to exit out 2 or 3 times before the form closes. How do I get the onclose function to ignore the lost focus. I tried using the beforeupdate and onerror events but there was too much code and I was getting lost. Any help is appreciated!!