Userform; User to complete all visible fields

dshah

New Member
Joined
Dec 19, 2017
Messages
2
[FONT=&quot]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=&quot]On data submission, data will be copied into an excel worksheet. [/FONT]
[FONT=&quot]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=&quot]1) How to run the code to check for blank entries on only visible fields in the form[/FONT]
[FONT=&quot]2) How to change the code to allow users to fill in missing data[/FONT]
[FONT=&quot]Thanks for your help. Below is as far as I got:[/FONT]
[FONT=&quot]Private Sub Submit_Click()[/FONT]
[FONT=&quot]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]
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
You can check the Visible property of the control for that.

And I don't see anything in this code that is preventing user to fill missing data.
 
Upvote 0
You can check the Visible property of the control for that.

And I don't see anything in this code that is preventing user to fill missing data.

Not sure I understand what you mean by check the visible property of the control for that..
 
Upvote 0
1) How to run the code to check for blank entries on only visible fields in the form
Just like you are checking the Value property of the control, check Visible property of the control:
Code:
If ctrl.Visible Then
    ' Control is visible
End If
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top