Help with modifying sub routine...

Posted on 2006-05-25
Last Modified: 2010-04-23
I have this Sub that is in my class.  It clears controls that are associated with the designated form, however, it will not clear any controls that are contained in my Tabcontrol.  Here is my code:

Public Sub CLEARDATA(ByVal frm As ContainerControl)

        For Each newControl As Control In frm.Controls
            If TypeOf (newControl) Is TextBox Then
                newControl.Text = ""
            ElseIf TypeOf (newControl) Is ComboBox Then
                newControl.Text = ""
            ElseIf TypeOf (newControl) Is ContainerControl Then
            End If

    End Sub
Question by:vilusion
    LVL 34

    Accepted Solution

    try it this way

    Public Sub CLEARDATA(ByVal collection As Control.ControlCollection)

                      For Each ctl As Control In collection
                            If ctl.Controls.Count > 0 Then
                            End If
                            If TypeOf (ctl) Is TextBox Then
                                  ctl.Text = ""
                            ElseIf TypeOf (ctl) Is ComboBox Then
                                  CType(ctl, ComboBox).SelectedIndex = -1
                            End If
                Catch ex As Exception
                End Try
          End Sub

    an example usage would be...


    Author Comment

    Worked great!  Thank you!

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now