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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining the type of control

Status
Not open for further replies.

subhavs

Programmer
Nov 27, 2000
54
US
Hi,

Can anyone tell me how I can determine what type of controls are used on a form (programmatically) ?

Can we use the Controls collection property of the Form object for this ?

Thanks in advance for the help,

- Subha :) Nothing is impossible, even the word impossible says I'm possible.
 
Subha,

This should help. Not sure what you want to do with the info you get back, so I've displayed it in a messagebox.

Dim i As Integer
For i = 0 To Form1.Controls.Count - 1
MsgBox TypeName(Form1.Controls(i))
Next

n.b. if you're looking for a particular type, you can use:

if TypeOf Form1.Controls(i) Is CheckBox then



Rob.
 
Thanks Rob, for the quick response.

I need to look for textboxes, that's the reason why I asked the question.

I am trying to write some kinda form level event that will highlight the text in a text box when the user navigates to it. The form can contain any number of text boxes, and it is a lot of code to use SelStart and SelLength for each one of them.

However, the TypeOfForm1.Controls(i) did not work for me. Do I have to include any references ?

Thanks for the help,

- Subha :) Nothing is impossible, even the word impossible says I'm possible.
 
Example TypeOf :

'Add 1 CommandButton and few TextBoxes To Your Form.
'Insert the following code to your form:

Private Sub Command1_Click()
Dim Contrl As Control
For Each Contrl In Form1.Controls
If (TypeOf Contrl Is TextBox) Then Contrl.Text = ""
Next Contrl
End Sub

Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX.

Download Demo version on my Site:
Promotions before 02/28/2001 (free source codebook),visite my site
 
How about having one form level procedure which is called from each "GotFocus" event?

It could "remove" any "highlighting" from all of the controls (TextBox, ListBox, ComboBox ...) and then do the highlighting for the one.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Thanks for all your responses guys.

Can you write a form-level event that will supercede any control-level events ?

For example - when the user clicks on any control, I would want a form level key-click event to kick off rather than the individual control's key-click event. If key-click events are defined individually then they should supercede the form-level key-click, but otherwise my form-level key-click should execute.

Am I making sense ? Wonder if this is possible in VB.

- Subha :) Nothing is impossible, even the word impossible says I'm possible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top