[FONT="]I have a userform that depends on various data types. When the user opens the form, all fields are hidden and based on the selection from drop down cetain fields are visible and others are hidden. [/FONT]
[FONT="]On data submission, data will be copied into an excel worksheet. [/FONT]
[FONT="]I’m trying to write a code to check if all visible fields are completed in the userform before the user submits data and if they are blank then prompt the user to complete the field. I’m struggling with 2 things:[/FONT]
[FONT="]1) How to run the code to check for blank entries on only visible fields in the form[/FONT]
[FONT="]2) How to change the code to allow users to fill in missing data[/FONT]
[FONT="]Thanks for your help. Below is as far as I got:[/FONT]
[FONT="]Private Sub Submit_Click()[/FONT]
[FONT="]Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is msforms.TextBox Or TypeOf ctrl Is msforms.ComboBox Or TypeOf ctrl Is DTPicker Then
If ctrl.Value = “” Then
Cancel = 1
ctrl.BackColor = vbRed
‘MsgBox “Complete all fields in red”
‘ctrl.SetFocus
End If
End If
Next[/FONT]
[FONT="]On data submission, data will be copied into an excel worksheet. [/FONT]
[FONT="]I’m trying to write a code to check if all visible fields are completed in the userform before the user submits data and if they are blank then prompt the user to complete the field. I’m struggling with 2 things:[/FONT]
[FONT="]1) How to run the code to check for blank entries on only visible fields in the form[/FONT]
[FONT="]2) How to change the code to allow users to fill in missing data[/FONT]
[FONT="]Thanks for your help. Below is as far as I got:[/FONT]
[FONT="]Private Sub Submit_Click()[/FONT]
[FONT="]Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is msforms.TextBox Or TypeOf ctrl Is msforms.ComboBox Or TypeOf ctrl Is DTPicker Then
If ctrl.Value = “” Then
Cancel = 1
ctrl.BackColor = vbRed
‘MsgBox “Complete all fields in red”
‘ctrl.SetFocus
End If
End If
Next[/FONT]