Jumat, 27 Mei 2011

RE: [MS_AccessPros] get control name associated with label

 

Hi Pam,

adding on to what John said ...

if a label is associated with a textbox or other control, it has no events. The only way it can have events is to NOT be associated.

> I need to reference the name of the control that the label
> is associated
> with, not the active control.

you can reference a control this way:
Me.controlname
or
Me("controlname")

~~~

looking at your code:

Call thisOrder(ActiveControl.Name, Screen.ActiveForm)

instead of using the name property of the ActiveControl, which won't be right, why not pass the name of the control you wish.

'~~~~~~~~~~~
Call thisOrder("txtPodNumber", Me)
'~~~~~~~~~~~

Maybe use ME instead of Screen.ActiveForm unless you are on a subform and want to refer to a parent

I would caution against embedding logic into controls, but another thing you can do is use the TAG property, which is the last property on the Other tab of the property sheet. It is not used by Access, you can write and read to it as you wish. This means, you could put the name of the control there and do this:

'~~~~~~~~~~~
'not recommended
Call thisOrder(ActiveControl.tag, Me)
'~~~~~~~~~~~

It is better to put the logic in the the code behind the form where you can compile and fix things quicker.

Warm Regards,
Crystal

*
(: have an awesome day :)
*

--- On Fri, 5/27/11, John Viescas wrote:

> Pam-
>
> Don't put the Click event procedure in the label - put it
> in the associated text
> box.  If the user clicks the associated label, the
> click event for the text box
> fires!
>
> John Viescas, author
> Microsoft Office Access 2010 Inside Out
> Microsoft Office Access 2007 Inside Out
> Building Microsoft Access Applications
> Microsoft Office Access 2003 Inside Out
> SQL Queries for Mere Mortals
> http://www.viescas.com/
> (Paris, France)
>
>
>
> -----Original Message-----
> From: Pamela Zimmerman

> Can anyone one tell me how I can reference a control
> associated with a
> label?
>
>
>
> Given the form has a label called lblPodNumber and a field
> called
> txtPodNumber
>
>
>
> I have this:
>
>
>
> Private Sub lblPodNumber_Click()
>
>
>
> Call thisOrder(ActiveControl.Name, Screen.ActiveForm)
>
>
>
> End Sub
>
>
>
> I need to reference the name of the control that the label
> is associated
> with, not the active control.  How can I do that?
>
>
>
> If possible, I would prefer not to use the actual label
> name (lblPodNumber),
> as I would like to keep this as reusable as possible. 
>
>
>
>
> Suggestions appreciated!
>
>
>
> Pam
>
>
>

__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar