Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please please help about looping through controls

Status
Not open for further replies.

access97to2000

Programmer
Aug 12, 2002
45
US
how to loop all the controls in a frame ? i have around 25 controls and i have to check them for blank.
 
Dim ctl As Control
For Each ctl In Form1.Controls
If ctl.Container Is Frame Then
'If TypeOf ctl Is TextBox Then
'End IF
End If
Next ctl
[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 

try this

This has a frame (Frame1) and two text boxes (Text1, Text2) with two labels (Label1, Label2) all inside or contained within Frame1 And Text3 with Label3 on the form.

[tt]Option Explicit

Private Sub Form_Load()

Dim C As Control

Text2.Text = ""
Text3.Text = ""
Label2.Caption = ""
Label3.Caption = ""

For Each C In Me.Controls

If C.Container Is Frame1 Then
If TypeOf C Is TextBox Then
If C.Text = "" Then
MsgBox C.Name & " is empty"
End If
ElseIf TypeOf C Is Label Then
If C.Caption = "" Then
MsgBox C.Name & " is blank"
End If
End If
End If
Next

End Sub

[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top