The following code works but it checks for all fields.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctrl As Control, strList As String
For each ctrl In Me.Controls
If ctrl.ControlType = acTextbox Or ctrl.ControlType = acComboBox Then
If Nz(ctrl,"") = "" Then strList = strList & ctrl.Controls(0).Caption & vbCrLf '<< caption was incorrectly "name"
End If
Next
If strList <> "" Then
strList = "The following fields are required:" & vbCrLf & strList
Msgbox strList
Cancel = True
End If
end sub
Since i only want to check some fields, and use control tag instead of control label, i modified the above code a bit to have the following which works as expected:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control, strList As String
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
If Nz(ctl, "") = "" And ctl.Tag <> "" Then
strList = strList & ctl.Tag & vbCrLf
End If
End If
Next
If strList <> "" Then
strList = "The following fields are required:" & vbCrLf & strList
MsgBox strList
Cancel = True
End If
end sub
Thank you for you time Micron. Thank you too June 7.