Possible to loop/iterate in Frame1 (in a vba userform) only all label?
in effect i have various label in frame1 and i need only this label, not the rest in userform
loop / iterate label in frame
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: loop / iterate label in frame
For example:
Code: Select all
Dim ctl As Control
For Each ctl In Me.Frame1.Controls
If TypeName(ctl) = "Label" Then
' Do something with the control
Debug.Print ctl.Name, ctl.Caption
End If
Next ctl
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4355
- Joined: 26 Apr 2010, 17:36
Re: loop / iterate label in frame
OPS...HansV wrote:For example:
Code: Select all
Dim ctl As Control For Each ctl In Me.Frame1.Controls If TypeName(ctl) = "Label" Then ' Do something with the control Debug.Print ctl.Name, ctl.Caption End If Next ctl
I need to iterate only to all label named:
B..
BB..
BBB...
my test code, i need to change the forecolr in vbred only to the label Left(TEST, 1) = "B":
Code: Select all
Dim CTL As Control
For Each CTL In Me.Frame1.Controls
TEST = CTL.Name
If Left(TEST, 1) = "B" Then
' Do something with the control
Me.CTL.Name.ForeColor = vbRed<<< error here
'Me.TEST.
End If
Next CTL
You do not have the required permissions to view the files attached to this post.
Last edited by sal21 on 25 Jun 2014, 19:25, edited 1 time in total.
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: loop / iterate label in frame
Change the line
to
Code: Select all
If TypeName(ctl) = "Label" Then
Code: Select all
If TypeName(ctl) = "Label" And ctl.Name Like "B*" Then
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4355
- Joined: 26 Apr 2010, 17:36
Re: loop / iterate label in frame
HansV wrote:Change the line
toCode: Select all
If TypeName(ctl) = "Label" Then
Code: Select all
If TypeName(ctl) = "Label" And ctl.Name Like "B*" Then
sorry me Hans but changed post with my new request if the label is matched ...
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: loop / iterate label in frame
It's difficult to help you if you keep on changing the question after each reply...
Best wishes,
Hans
Hans
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: loop / iterate label in frame
CTL.Name does not have a ForeColor. CTL has a ForeColor.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4355
- Joined: 26 Apr 2010, 17:36
Re: loop / iterate label in frame
Sorry if i post on old 3d...HansV wrote:CTL.Name does not have a ForeColor. CTL has a ForeColor.
i need if to check if at least texbox have a no null value ...
Code: Select all
Dim cCont As Control
For Each cCont In Me.Controls
If TypeName(cCont) = "TextBox" And cCont.Name Like "P*" Then
'here the counter +1 to check the condition but how to intercept a blank value in tetxbox?
End If
Next cCont
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: loop / iterate label in frame
Like this:
Code: Select all
Dim cCont As Control
Dim lConta As Long
For Each cCont In Me.Controls
If TypeName(cCont) = "TextBox" And cCont.Name Like "P*" Then
If cCont.Value <> "" Then
lConta = lConta + 1
End If
End If
Next cCont
If lConta = 0 Then
' All text boxes are blank
Else
' At least one text box is not blank
End If
Best wishes,
Hans
Hans