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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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