#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 88
Default Control on Form

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

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Control on Form

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
---------------
Jacob Skaria


"leerem" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Control on Form

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
---------------
Jacob Skaria


"leerem" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Control on Form

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)

"leerem" wrote in message
...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2007 Form Control/ActiveX Control font difference Nikko963 Excel Discussion (Misc queries) 0 April 15th 09 04:21 PM
toolbars: form vs control AFJr Excel Discussion (Misc queries) 1 August 2nd 07 11:16 AM
form control - check box irene c New Users to Excel 1 February 2nd 07 09:23 PM
Using form control names in SQL AaronC Excel Discussion (Misc queries) 0 July 14th 05 05:13 PM
How do I set up and use a group box form control? Grizz905 Excel Discussion (Misc queries) 1 January 20th 05 10:14 PM


All times are GMT +1. The time now is 05:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"