Thank you for reading my post.
I am using code provided by TheAceMan1 to perform required field entry validation. It works as expected for the main form and the 1st nested sub form, but does not seem to work on either the 2nd or subsequent nested sub forms.
I am tracking Customers, their contracts with us and each of the services that make up each contract. The form structure I'm using is a main form with nested sub forms.
Main form - "frmCustomerResEnter" - RS is "tblCustomers", Pk "CustomerID"
1st Sub Form - "sfrmContracts" - RS is "tblContracts", Pk "ContractID", Fk "CustomerID"
2nd Sub Form - "sfrmServiceItems" - RS is "tblServiceItems", Pk "ServiceItemID", Fk's "ContractID" and "ServiceTypeItemID"
3rd Sub Form - "sfrmHavcItems" - RS is tblHvacItems, Pk "HavcItemID", Fk "ServiceTypeItemID" (a composite key of "ServiceItemID" & "SerivceTypeID")
(There are 7 of the above sub forms, each for a different type of service. Each becomes visible based on the value entered in "cboServiceItemID" of "sfrmServiceItems")
I have put a question mark ? in Tag property of each of the required fields on each of the forms and placed the following code in the Before Update event of each of those forms.
Can anyone provide any insight as to why it would not work it the 2nd and subsequent sub forms? Any help would be much appreciated.
I am using code provided by TheAceMan1 to perform required field entry validation. It works as expected for the main form and the 1st nested sub form, but does not seem to work on either the 2nd or subsequent nested sub forms.
I am tracking Customers, their contracts with us and each of the services that make up each contract. The form structure I'm using is a main form with nested sub forms.
Main form - "frmCustomerResEnter" - RS is "tblCustomers", Pk "CustomerID"
1st Sub Form - "sfrmContracts" - RS is "tblContracts", Pk "ContractID", Fk "CustomerID"
2nd Sub Form - "sfrmServiceItems" - RS is "tblServiceItems", Pk "ServiceItemID", Fk's "ContractID" and "ServiceTypeItemID"
3rd Sub Form - "sfrmHavcItems" - RS is tblHvacItems, Pk "HavcItemID", Fk "ServiceTypeItemID" (a composite key of "ServiceItemID" & "SerivceTypeID")
(There are 7 of the above sub forms, each for a different type of service. Each becomes visible based on the value entered in "cboServiceItemID" of "sfrmServiceItems")
I have put a question mark ? in Tag property of each of the required fields on each of the forms and placed the following code in the Before Update event of each of those forms.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate
Dim Msg As String, Style As Integer, Title As String
Dim DL As String, ctl As Control
DL = vbNewLine & vbNewLine
For Each ctl In Me.Controls
If ctl.Tag = "?" Then
If Trim(ctl & "") = "" Then
Msg = ctl.Name & " Is a Required Field!" & DL & _
"Please complete this field in order to continue . . ."
Style = vbCritical + vbOKOnly
Title = "Required Data Error"
MsgBox Msg, Style, Title
ctl.SetFocus
Cancel = True
Exit For
End If
End If
Next
Exit_Form_BeforeUpdate:
Exit Sub
Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate
End Sub