Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine VBA Form Control Type

Status
Not open for further replies.

Annelies

Programmer
Nov 25, 2001
72
0
0
Hi

I have some code that loops through all controls on a form. I want to be able to determine what type (eg, Combobox, TextBox, CommandButton etc) each control is.

My code looks like:

Dim c as Control
For Each c In Me.Controls
If (c.?? = TextBox) Then
'Do something
End If
Next c

TypeOf doesn't work.
FormControlType property doesn't work.

Surely there must be an easy way to do this!?!

Any help gratefully received!

Annelies
 
Use TypeName(ObjectVariable) function

combo
 

TypeOf does work but you may need to qualify the type name to be sure you are checking the right one, for example
Code:
[blue]If TypeOf c Is MSForms.CheckBox Then [/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top