Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / January 2008

Tip: Looking for answers? Try searching our database.

Return the name of the object I click on in a form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Dumay - 17 Jan 2008 19:46 GMT
Hi,

How do I go about returning the name of an object on a form. For example if
I set the "On Click" event procedure on a rectangle object to return:

MsgBox Me.Name

I get the form name. What I want to  do is click on the object and be abe to
reference it's properties such as Tag to run other code based in these values.

As always any assistance is greatly appreciated.

Regards,

John Dumay
AG - 17 Jan 2008 20:49 GMT
For the name of the control try
Screen.ActiveControl.Name

For the control itself use
Screen.ActiveControl

Signature

AG
Email: discussATadhdataDOTcom

> Hi,
>
[quoted text clipped - 14 lines]
>
> John Dumay
John Dumay - 17 Jan 2008 21:39 GMT
Hi AG,

Thanks for the reply. Yes I have tried that option but the Rectangle object
cannot get the focus so it cannot return the name of the clicked object.
Instead it returns the name of the object which has focus. (In my case a
toggle button)

Regards,

John

> For the name of the control try
> Screen.ActiveControl.Name
[quoted text clipped - 20 lines]
> >
> > John Dumay
AG - 18 Jan 2008 02:40 GMT
All I can think of would be to pass the name of the control to your
procedure.

For instance:
Private Sub Rectangle1_Click()
   Call YourControlFunction("Box44")    'for controls that can't get focus,
pass the name
End Sub

Private Sub TextBox1_Click()
   Call YourControlFunction    'for controls that can get focus, no need to
pass its name
End Sub

If you have a lot of controls, you can save some work by selecting all the
controls that can get focus and putting '=YourControlFunction()' in the 'On
Click' event.

Private Function YourControlFunction(Optional byval strControlName As String
= "")
Dim ctL as Access.Control
   If strControlName <> "" Then
       Set ctL = Me(strControlName)
   Else
       Set ctL = Screen.ActiveControl
   End If
   If ctL.ControlType = acTextBox Then
       Do something
   ElseIf ctL.ControlType = acComboBox Then
       Do something else
   End If
End Function
Signature


AG
Email: discussATadhdataDOTcom

> Hi AG,
>
[quoted text clipped - 34 lines]
>> >
>> > John Dumay
John Dumay - 18 Jan 2008 04:51 GMT
Hi AG,

Looks like a perfectly good solution. Will give it a go and let you know.

Thanks for your assistance.

Regards,

John Dumay

> All I can think of would be to pass the name of the control to your
> procedure.
[quoted text clipped - 66 lines]
> >> >
> >> > John Dumay
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.