If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Refer to control in procedure
I have a form with rectangles on it which display the shape of offices. My
Code is the following: Private Sub shpAB12567C_Click() Call SelectLoc "shpAB12567C" Me.shpAB12567C.BackColor = vbRed End Sub Is there a way to pickup the sub name/control name from within the procedure, to save me from specifying it for each control on the form. E.g. I'm looking to do the following so I can just copy & paste for each control. Private Sub shpAB12567C_Click() Call SelectLoc Me.ControlName Me.ControlName.BackColor = vbRed End Sub I have looked at active control but it doesn't work with rectangle shapes. thanks |
#2
|
|||
|
|||
Refer to control in procedure
You would need only one function to do it a little differently. I would
suggest this function go in a standard module so it could be used by any form. Using this approach, you don't need to create any code in your form. Just put the following in the text box for the click event in the properties dialog for each control you want to affect: =SetColor() Public Function SetColor() As Boolean Dim frm As Form Dim ctl As Control Set frm = Screen.ActiveForm Set ctl = frm.ActiveControl Call SelectLoc ctl.Name ctl.BackColor = vbRed Set ctl = Nothing Set frm = Nothing End Function -- Dave Hargis, Microsoft Access MVP "Will" wrote: I have a form with rectangles on it which display the shape of offices. My Code is the following: Private Sub shpAB12567C_Click() Call SelectLoc "shpAB12567C" Me.shpAB12567C.BackColor = vbRed End Sub Is there a way to pickup the sub name/control name from within the procedure, to save me from specifying it for each control on the form. E.g. I'm looking to do the following so I can just copy & paste for each control. Private Sub shpAB12567C_Click() Call SelectLoc Me.ControlName Me.ControlName.BackColor = vbRed End Sub I have looked at active control but it doesn't work with rectangle shapes. thanks |
#3
|
|||
|
|||
Refer to control in procedure
Hi,
nope, because the procedure belongs to the form, not to the control, and can be, technically, called from any where, form code, within the form-module... (such as TWO controls calling the same _Click procedure IS doable), so no UNIQUE control is assigned to a _Click procedure... But you can try to play with Screen.ActiveControl or Screen.PreviousControl. Note that code using such control is very hard to debug "step by step" since the Screen Active control is modified live by activation of the debugger screen, though the debugging process. Hoping it may help, Vanderghast, Access MVP "Will" wrote in message ... I have a form with rectangles on it which display the shape of offices. My Code is the following: Private Sub shpAB12567C_Click() Call SelectLoc "shpAB12567C" Me.shpAB12567C.BackColor = vbRed End Sub Is there a way to pickup the sub name/control name from within the procedure, to save me from specifying it for each control on the form. E.g. I'm looking to do the following so I can just copy & paste for each control. Private Sub shpAB12567C_Click() Call SelectLoc Me.ControlName Me.ControlName.BackColor = vbRed End Sub I have looked at active control but it doesn't work with rectangle shapes. thanks |
#4
|
|||
|
|||
Refer to control in procedure
This is a good point you bring up. I often forget to warn people code using
ActiveControl, PreviousControl, or ActiveForm don't do will in debug. But then I write code that doesn't need to be debugged -- Dave Hargis, Microsoft Access MVP "Michel Walsh" wrote: Hi, nope, because the procedure belongs to the form, not to the control, and can be, technically, called from any where, form code, within the form-module... (such as TWO controls calling the same _Click procedure IS doable), so no UNIQUE control is assigned to a _Click procedure... But you can try to play with Screen.ActiveControl or Screen.PreviousControl. Note that code using such control is very hard to debug "step by step" since the Screen Active control is modified live by activation of the debugger screen, though the debugging process. Hoping it may help, Vanderghast, Access MVP "Will" wrote in message ... I have a form with rectangles on it which display the shape of offices. My Code is the following: Private Sub shpAB12567C_Click() Call SelectLoc "shpAB12567C" Me.shpAB12567C.BackColor = vbRed End Sub Is there a way to pickup the sub name/control name from within the procedure, to save me from specifying it for each control on the form. E.g. I'm looking to do the following so I can just copy & paste for each control. Private Sub shpAB12567C_Click() Call SelectLoc Me.ControlName Me.ControlName.BackColor = vbRed End Sub I have looked at active control but it doesn't work with rectangle shapes. thanks |
#5
|
|||
|
|||
Refer to control in procedure
:-)
Vanderghast, Access MVP "Klatuu" wrote in message ... This is a good point you bring up. I often forget to warn people code using ActiveControl, PreviousControl, or ActiveForm don't do will in debug. But then I write code that doesn't need to be debugged -- Dave Hargis, Microsoft Access MVP "Michel Walsh" wrote: Hi, nope, because the procedure belongs to the form, not to the control, and can be, technically, called from any where, form code, within the form-module... (such as TWO controls calling the same _Click procedure IS doable), so no UNIQUE control is assigned to a _Click procedure... But you can try to play with Screen.ActiveControl or Screen.PreviousControl. Note that code using such control is very hard to debug "step by step" since the Screen Active control is modified live by activation of the debugger screen, though the debugging process. Hoping it may help, Vanderghast, Access MVP "Will" wrote in message ... I have a form with rectangles on it which display the shape of offices. My Code is the following: Private Sub shpAB12567C_Click() Call SelectLoc "shpAB12567C" Me.shpAB12567C.BackColor = vbRed End Sub Is there a way to pickup the sub name/control name from within the procedure, to save me from specifying it for each control on the form. E.g. I'm looking to do the following so I can just copy & paste for each control. Private Sub shpAB12567C_Click() Call SelectLoc Me.ControlName Me.ControlName.BackColor = vbRed End Sub I have looked at active control but it doesn't work with rectangle shapes. thanks |
Thread Tools | |
Display Modes | |
|
|