Check all textboxes

S

stewart

how can i get this too work. What am I doing wrong? My code is just
a guess based on other snipets I have seen and used.

Private Sub CommandButton1_Click()
For Each Control In
ThisWorkbook.VBProject.VBComponents("frmEvaluation").Designer.Controls(MultiPage1).Pages(0)
If TypeOf Control Is MSForms.TextBox Then
If Control.Value = "" Then
MsgBox "fill it"
Else
MsgBox "its filled"
End If
End If
Next Control

I want to check all of the textboxes on page 0 to make sure that they
conatain an input from the user.
 
J

Joel

try this. If you have shapes like rectangle it will also look for the text
boxes in shapes.


Sub CommandButton1_click()

For Each Control In Sheets("sheet1").Shapes

If Control.Type = msoTextBox Then

If Control.DrawingObject.Caption = "" Then
MsgBox "fill it"
Else
MsgBox "its filled"
End If
End If

Next Control
End Sub
 
M

merjet

Try this instead:
For Each Control In Me.Controls

Also, it's a good habit to avoid using variable names that can lead to
problems. For example, use ctrl rather than Control.

Hth,
Merjet
 
S

stewart

merjet,
this does work but is there a way to specify a certain page in a
multipage control. Also how do I stop it once it has found an empty
textbox.
 
M

merjet

merjet,
this does work but is there a way to specify a certain page in a
multipage control. Also how do I stop it once it has found an empty
textbox.

You can specify the page, stop the Sub and set the focus on the empty
TextBox as follows.

Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.TextBox And ctrl.Parent.Name = "Page1"
Then
If ctrl.Value = "" Then
MsgBox "fill it"
ctrl.SetFocus
Exit Sub
Else
MsgBox "its filled"
End If
End If
Next ctrl

Hth,
Merjet
 
S

stewart

Great. Works perfectly thank you

You can specify the page, stop the Sub and set the focus on the empty
TextBox as follows.

Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.TextBox And ctrl.Parent.Name = "Page1"
Then
If ctrl.Value = "" Then
MsgBox "fill it"
ctrl.SetFocus
Exit Sub
Else
MsgBox "its filled"
End If
End If
Next ctrl

Hth,
Merjet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top