Control

  • Thread starter Thread starter Treebeard
  • Start date Start date
T

Treebeard

Is there anyway to determine the "Control Type" on a form in VBA?

Can I determine whether a control is a Text Box or a Label from its
properties?

Thanks

Jack
 
The ControlType property, e.g.:
Forms!Form1!Text0.ControlType

You can interpret the number returned with this function:

Function ControlTypeName(n As Long) As String
'Purpose: Return the name of the ControlType.
'Note: The ControlType returns a Byte, but the constants are Long.
Dim strReturn As String

Select Case n
Case acBoundObjectFrame
strReturn = "Bound Object Frame"
Case acCheckBox
strReturn = "Check Box"
Case acComboBox
strReturn = "Combo Box"
Case acCommandButton
strReturn = "Command Button"
Case acCustomControl
strReturn = "Custom Control"
Case acImage
strReturn = "Image"
Case acLabel
strReturn = "Label"
Case acLine
strReturn = "Line"
Case acListBox
strReturn = "List Box"
Case acObjectFrame
strReturn = "Object Frame"
Case acOptionButton
strReturn = "Object Button"
Case acOptionGroup
strReturn = "Option Group"
Case acPage
strReturn = "Page (of Tab)"
Case acPageBreak
strReturn = "Page Break"
Case acRectangle
strReturn = "Rectangle"
Case acSubform
strReturn = "Subform/Subrport"
Case acTabCtl
strReturn = "Tab Control"
Case acTextBox
strReturn = "Text Box"
Case acToggleButton
strReturn = "Toggle Button"
Case Else
strReturn = "Unknown: type" & n
End Select
ControlTypeName = strReturn
End Function
 
Allen,

I tried using the ControlType property but it returns 139 for both a text
box and a label????

Jack
 
Something is certainly wrong.

A text box is 109 and a label is 100 and if you check the equality in the
debug window, you'll get:

?acTextbox = acLabel
False

which, of course is correct. What's more there is no controltype of 139.

You can also use TypeOf Control as in:

Dim rpt as Report
Dim ctl as Control

Set rpt = Me
For Each ctl In rpt.Controls
If TypeOf ctl is acLabel Then
'whatever you want to do
ElseIf TypeOf ctl is acTextbox Then
'whatever else you want to do
End If
Next ctl

--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Back
Top