Control on Form

  • Thread starter Thread starter leerem
  • Start date Start date
L

leerem

I'm haveing a problem with the following code to clear the contents of
controls on a UserForm.

Sub ClearForm()

Dim Ctl as Control

For Each Ctl in NewVehicle ' name of form
If TypeOf Ctl Is Textbox then
Ctl.Text =vbNullString

ElseIf TypeOf Ctl Is CheckBox then
Ctl.Value = UnChecked

ElseIf TypeOf Ctl Is ComboBox then
Ctl.ListIndex = -1
End if
Next Ctl
End Sub


This is all the Controls on the Form. But I get the Message " object doesn't
support this Property or method.
Do i need to list each and every control on the form ?

Regards
Lee
 
For Each Ctl in NewVehicle

OR

Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
ctrl.Text = vbNullString
End If
Next

If this post helps click Yes
 
For Each Ctl in NewVehicle

OR

Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
ctrl.Text = vbNullString
End If
Next

If this post helps click Yes
 
Oops. Please ignore the previous post

For Each Ctl in NewVehicle.Controls
OR
For Each Ctl in Me.Controls


If this post helps click Yes
 
Oops. Please ignore the previous post

For Each Ctl in NewVehicle.Controls
OR
For Each Ctl in Me.Controls


If this post helps click Yes
 
Sub ClearForm()

Dim Ctl As Control

For Each Ctl In NewVehicle.Controls ' name of form
If TypeOf Ctl Is msforms.TextBox Then
Ctl.Text = vbNullString

ElseIf TypeOf Ctl Is msforms.CheckBox Then
Ctl.Value = Unchecked

ElseIf TypeOf Ctl Is ComboBox Then
Ctl.ListIndex = -1
End If
Next Ctl
End Sub



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Sub ClearForm()

Dim Ctl As Control

For Each Ctl In NewVehicle.Controls ' name of form
If TypeOf Ctl Is msforms.TextBox Then
Ctl.Text = vbNullString

ElseIf TypeOf Ctl Is msforms.CheckBox Then
Ctl.Value = Unchecked

ElseIf TypeOf Ctl Is ComboBox Then
Ctl.ListIndex = -1
End If
Next Ctl
End Sub



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Back
Top