Hello everyone. Newby VBA learner here. I'm working on a code that checks all blank/null text fields and combo boxes in a form and notifies the user if a field is not filled. The code below works if all fields are required, but I can't use it on forms that have fields that are not really mandatory. I've read somewhere on the net to use tags on the controls i want to skip checking, but that's where i get lost. any help?
here's the code i'm working on.
here's the code i'm working on.
Code:
Dim stdResponse As Variant
Dim ctl As Control
' Enumerate Controls collection.
For Each ctl In Me.Controls
' Check to see if control is text box.
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
' Set control properties.
With ctl
If ctl.Value = "" Or IsNull(ctl.Value) Then GoTo 20
End With
End If
Next ctl
DoCmd.Close
Exit Sub
20:
stdResponse = MsgBox("You have not completed the " & ctl.Name & "." _
& vbCr & "This is a required field, do you want to complete it now?" _
& vbCr & vbCr & "Select YES to return to the form." & vbCr & vbCr _
& "Select NO to exit the form SAVING the record.", vbYesNo, "Missing Data")
If stdResponse = vbYes Then
ctl.SetFocus
Exit Sub
Else 'vbNo
Me.Undo
DoCmd.Close
DoCmd.OpenForm "frmMasterPortal"
End If