Identify Image Control Name

MLUCKHAM

Registered User.
Local time
Today, 21:34
Joined
Jul 23, 2013
Messages
89
Got a right tricky one here.

I have a global function which I have hooked onto the onClick event of controls. Currently I am using commandButtons as my control of choice. In my function I can then reference Forms.ActiveControl which is no problem.

However, for lots of reasons I really need to use Image controls. Now, my problem. Image Controls have an Onclick Event, but they do not get focus so the Forms.ActiveControl will not work.

How can I identify the image control that has generated the click event if the control itself does not get focus and so cannot be referenced by ActiveControl? Working on a possibly work around, but could do with the best brains in Access on the case!
 
Simple solution, create a Public variable ..
Code:
Public activeCtrlName As String
Then on click of every image just code the name of the image control name to the public variable, you can then use the Public variable to do your operation, instead of ActiveControl.
 
Thanks for your reply, but this is too clunky. I don't want to code each control individually. I want to use a global function, attach it to all of the controls like "=SelectObject()" and then in the function code reference the calling control. Works a treat with any control that can take focus e.g. commandButton as I can use Form.ActiveControl, but for the image control cannot do (even though it has the event) as it does not take focus.
 
Check out this workaround!

I have created the following function: -

Code:
Public Function WhatControl(ByVal MouseX As Single, ByVal MouseY As Single) As Control


    For i = 0 To Me.Controls.Count - 1
    
        If Me.Controls(i).Left < MouseX And (Me.Controls(i).Left + Me.Controls(i).Width) > MouseX Then 'Control is in the right horizontal position
            If Me.Controls(i).Top < MouseY And (Me.Controls(i).Top + Me.Controls(i).Height) > MouseY Then ' We have found it!)
                Set WhatControl = Me.Controls(i)
                Exit For
            End If
        End If
    
    Next i
    

End Function

On the mouseDown event on the Image control I pass the X and Y parameters to this bad boy and it works out which control the mouse was clicking! Works (as long as you do not have image controls on top of each other).

Next step is to now inject the code dynamically onto the form for each control that is placed. I have that sorted I think.

Thanks for anyone who looked at this, but I am sorted I think!
 

Users who are viewing this thread

Back
Top Bottom