Form subs

  • Thread starter Thread starter mlujan
  • Start date Start date
M

mlujan

Guest
Hello all,
is there a way in a sub routine to determine the name of the calling control without explicitly referencing it?

For Example, let's say I have a control and I'm putting code behind it's MouseMove event. It is in this event that I'm trying to reference the control's name without having to type in Me!MyControl because I want to create a generic function to handle the event for mutiple instances of similar objects.
 
Try screen.activecontrol

This refers to the control that currently has focus

e.g.

screen.activecontrol.enabled = false

[This message has been edited by Jimbob (edited 05-21-2002).]
 
Fist off, Thanks for the Help Jimbob.

So say I have four rectangle boxes on a form. When my mouse goes over them, do they receive the focus? It seems that they do not since when I try to use ActiveControl, I get an error 'expression requires the control to be inthe active window.' Here's is a bit of the code...
Code:
' Begin Code

Dim objRect As Rectangle
Const lngYellow As Long = 65535
Const lngBlue As Long = 16763904


Private Sub Box0_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set objRect = Screen.ActiveControl    '<---Error is here
Call choosebox(objRect, True)
End Sub


Sub choosebox(objBox As Rectangle, bSwitch As Boolean)
Select Case bSwitch
    Case True
        objBox.BackColor = lngBlue
    Case False
        objBox.BackColor = lngYellow
End Select
End Sub


[This message has been edited by mlujan (edited 05-21-2002).]
 
Unfortunately you have to give the control focus for it to be the activecontrol. ie by click ing on it.

Just had a thought though....

Maybe you could somehow use the On MouseOver event to set the focus to the control...thus making it the screen.activecontrol...

I haven't got time to try this myself but it's a thought....

smile.gif
 
Try this mlujan:

Call choosebox (Me!Box0, true)

This way you are passing the control object directly. Since each box will have its own Box?_MouseMove routine, the choosebox routine can still be generic.

Hope this helps,
Jeff
 

Users who are viewing this thread

Back
Top Bottom