Detect type of control in userForm.

J

Joe

Hi,
I missed out code portion for my last posted question. (Only combox can be
detected but not textbox). My code attached here, please suggest if any way I
can loop though all controls in my form.
*********
For each ctl in me.Controls
If Typeof ctl Is TextBox or Typeof ctl is ComboBox then
'OK....
End if
Next
*********

regards,
 
C

Charles Maxson

Joe,

You are very close here; its too bad MSFT was not consistent with this (or
least documented it better). But all you need to do is refer to your textbox
type like this:

MSForms.TextBox

and it will work.....


Private Sub UserForm_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.TextBox Or TypeOf ctl Is ComboBox Then
MsgBox ctl.Name
End If
Next
End Sub
 
J

Joe

Charles,
It works. Thanks a lot.
Joe

Charles Maxson said:
Joe,

You are very close here; its too bad MSFT was not consistent with this (or
least documented it better). But all you need to do is refer to your textbox
type like this:

MSForms.TextBox

and it will work.....


Private Sub UserForm_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.TextBox Or TypeOf ctl Is ComboBox Then
MsgBox ctl.Name
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top