I want to print out the values of certain aspects of the various controls on
a user form. However, different controls support values that other controls
do not. So if I try to get the ".text" value of a checkbox, I will get an
error. Likewise, if I try to get a ".caption" value of a textbox = error.
Is there a way to determine the 'type' of control that is being 'seen,'
something like:
For Each oControl in MyForm.Controls
atype=oControl.type (this is not a valid value) <<<<<
If atype="Checkbox" then
'do this
elseif atype = "Textbox" then
'do this
etc.
Helmut Weber - 29 Apr 2007 09:45 GMT
Hi Ed,
maybe "TypeName" helps, in principle:
Private Sub CommandButton1_Click()
Dim oCtrl As Control
For Each oCtrl In Me.Controls
MsgBox TypeName(oCtrl)
Next
End Sub

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Perry - 29 Apr 2007 09:57 GMT
Various, here's one
for each ctl in me.controls
debug.print typename(ctl)
next
--
Krgrds,
Perry
System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
>I want to print out the values of certain aspects of the various controls
>on a user form. However, different controls support values that other
[quoted text clipped - 12 lines]
> 'do this
> etc.
Beth Melton - 29 Apr 2007 20:37 GMT
Use TypeOf. Such as:
For Each oControl In MyForm.Controls
If TypeOf oControl Is TextBox Then
'do this
ElseIf TypeOf oControl Is CheckBox Then
'do this
End If
Next oControl

Signature
Please post all follow-up questions to the newsgroup. Requests for
assistance by email can not be acknowledged.
~~~~~~~~~~~~~~~
Beth Melton
Microsoft Office MVP
Co-author of Word 2007 Inside Out:
http://www.microsoft.com/MSPress/books/9801.aspx#AboutTheBook

Signature
Word FAQ: http://mvps.org/word
TechTrax eZine: http://mousetrax.com/techtrax/
MVP FAQ site: http://mvps.org/
>I want to print out the values of certain aspects of the various controls
>on a user form. However, different controls support values that other
[quoted text clipped - 12 lines]
> 'do this
> etc.
Tony Jollans - 29 Apr 2007 21:46 GMT
Be very careful using TypeOf. It can catch you out.
If TypeOf oControl Is CheckBox Then
will fail for a checkbox on a userform because it will actually test against
a Word Form Checkbox Control and not a Userform Checkbox Control. You must
be specific about which type of Checkbox you want ....
If TypeOf oControl Is MSForms.CheckBox Then
should work. The more general TypeName works because it just compares names
as strings, not object types.

Signature
Enjoy,
Tony Jollans
Microsoft Word MVP
> Use TypeOf. Such as:
>
[quoted text clipped - 36 lines]
>> 'do this
>> etc.
Beth Melton - 30 Apr 2007 03:24 GMT
Ah! Thanks for the correction, Tony. :-)

Signature
Please post all follow-up questions to the newsgroup. Requests for
assistance by email can not be acknowledged.
~~~~~~~~~~~~~~~
Beth Melton
Microsoft Office MVP
Co-author of Word 2007 Inside Out:
http://www.microsoft.com/MSPress/books/9801.aspx#AboutTheBook

Signature
Word FAQ: http://mvps.org/word
TechTrax eZine: http://mousetrax.com/techtrax/
MVP FAQ site: http://mvps.org/
> Be very careful using TypeOf. It can catch you out.
>
[quoted text clipped - 49 lines]
>>> 'do this
>>> etc.
Ed - 30 Apr 2007 12:13 GMT
Thank you all. It works great!
Ed