0

I cannot figure out why the code below will not work. The first list box displays all of the controls except the textboxes. Of course, the MsgBox is doing nothing - since it is only looking for textboxes. Why is it not recognizing the textboxes? By the way, I have changed the names on some of my textboxes because I have so many. Can it not recognize what type of control it is if I have changed the name?

    Dim ctl As Control
    For Each ctl In Me.Controls
        ListBox1.Items.Add(ctl.Name)
        If TypeOf ctl Is TextBox Then
            MsgBox(ctl.Name)
            'validate that it is numeric
            If ctl.Text = "" Then
                'if not show error and exit sub
                MessageBox.Show("Please fill all blanks.")
                Exit Sub
            End If
        End If
    Next

I appreciate the help.

jrod404
  • 3
  • 1
  • My crystal ball says that the textboxes are in a container control that is a child of your form. The For Each loop looks only in `Me.Controls`. – Cody Gray - on strike May 15 '14 at 13:01
  • Error 1 Expression of type 'System.Windows.Forms.ContainerControl' can never be of type 'System.Windows.Forms.TextBox'. – jrod404 May 15 '14 at 13:14

0 Answers0