Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Clear all text boxes on a form in a forEach loop
Message
From
17/12/2002 15:14:04
 
 
To
17/12/2002 15:04:28
General information
Forum:
Visual Basic
Category:
Other
Miscellaneous
Thread ID:
00733822
Message ID:
00733825
Views:
20
This message has been marked as the solution to the initial question of the thread.
Vince,

You need to check that the type of the control is the one you want to affect. If your command loop is running as you put it here you are disabling all controls on the form, not just command buttons. What you need to do is the following:
   For Each ctrl In xObj.Controls
      If TypeOf ctrl Is CommandButton Then
         ctrl.Enabled = Not ctrl.Enabled
      End If
   Next
For the text boxes the check is TextBox, and you want to use the Text property instead of the Enabled as in the example above. Your text box example errors because some controls don't have a Text property. HTH

>I recently used the algorithm:
>
>Public Sub setPropsOnNavRoutineButtons(condition)
> ' Loops through each control on the form and sets the enabled condition
> Dim formControl As Control
> For Each formControl In frmNavRoutines.Controls()
> formControl.Enabled = condition
> Next formControl
>End Sub
>
>to enable/disable all the command buttons on a form.
>
>I now have a need to clear all textboxes on a form with controls other than just text boxes.
>
>I tried:
>
>Public Sub clearFields()
> 'Loops through each textbox on the form and sets text = ""
> Dim tBox As textBox
> 'For Each textBox In frmHomeSchoolTable.Controls()
> For Each tBox In gActiveForm.Controls()
> tBox.Text = ""
> Next tBox
>End Sub
>
>Blows on the for each statement (data type mismatch). Any ideas??
>thanx
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform