A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Refer to control in procedure



 
 
Thread Tools Display Modes
  #1  
Old January 4th, 2007, 02:56 PM posted to microsoft.public.access.forms
Will
external usenet poster
 
Posts: 2
Default 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  
Old January 4th, 2007, 04:15 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default 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  
Old January 4th, 2007, 04:38 PM posted to microsoft.public.access.forms
Michel Walsh
external usenet poster
 
Posts: 2,404
Default 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  
Old January 4th, 2007, 04:53 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default 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  
Old January 4th, 2007, 05:49 PM posted to microsoft.public.access.forms
Michel Walsh
external usenet poster
 
Posts: 2,404
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:56 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.