what object(combo box or text box) is the current selected object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Guys,

Is it possible to determine which object on a form is currently selected,
and have the name of the object placed in a variable string. For instance if
I had a combo box called combo1 and someone updated information in it, how do
I get the name of the combo box in a string named "str" only when the combo1
has been updated. .ie
Dim str as string

If there is several objects on a form I want the variable string "str" to be
updated with all the names of the objects when they are updated.

Can anybody help??
 
Examine:
Form.ActiveControl.ControlType

If you want the value returned as a name, use 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
 
Thannks Allen,

One last question where would I put this code??

Do I put this code under each Object on the form or under the forms main
control such as the "On Current", or "On load"...

Please advise!

All help really appreciated
 
Your original question was about determining when a control was updated. If
that is still the goal, the AfterUpdate event of each field would seem to be
the most logical event to use.
 
Back
Top