PC Review


Reply
Thread Tools Rate Thread

Check all textboxes

 
 
stewart
Guest
Posts: n/a
 
      7th May 2007
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.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      7th May 2007
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

"stewart" wrote:

> 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.
>
>

 
Reply With Quote
 
merjet
Guest
Posts: n/a
 
      7th May 2007
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


 
Reply With Quote
 
stewart
Guest
Posts: n/a
 
      7th May 2007
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.


On May 7, 1:16 pm, merjet <mer...@comcast.net> wrote:
> 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



 
Reply With Quote
 
merjet
Guest
Posts: n/a
 
      7th May 2007
On May 7, 1:35 pm, stewart <smccallis...@gmail.com> wrote:
> 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

 
Reply With Quote
 
stewart
Guest
Posts: n/a
 
      7th May 2007
Great. Works perfectly thank you

On May 7, 3:15 pm, merjet <mer...@comcast.net> wrote:
> On May 7, 1:35 pm, stewart <smccallis...@gmail.com> wrote:
>
> > 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subform with RecordSource and Textboxes - Textboxes not editable? juvi Microsoft Access Form Coding 9 5th Dec 2008 06:34 PM
Show Results in TextBoxes, ONLY if All TextBoxes have Data in them =?Utf-8?B?Unlhbkg=?= Microsoft Excel Programming 3 19th Nov 2007 03:30 PM
If Then's for 12 textboxes to check if they are empty. =?Utf-8?B?QmVlcnRqZQ==?= Microsoft Excel Misc 3 27th Oct 2005 02:34 PM
check is input textboxes is numeric on userform Jean-Pierre D via OfficeKB.com Microsoft Excel Programming 7 16th Aug 2005 08:15 PM
Form with cells and TextBoxes...how to TAB to textboxes? Toby Erkson Microsoft Excel Discussion 2 6th Oct 2004 11:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:42 PM.