Selasa, 31 Mei 2011

RE: [MS_AccessPros] get control name associated with label

 

Pam-

You got it! If you were to put that code in the Click event of the associated
Text Box, it would run when you click the label.

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: MS_Access_Professionals@yahoogroups.com
[mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of Pamela Zimmerman
Sent: Tuesday, May 31, 2011 9:57 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: RE: [MS_AccessPros] get control name associated with label

Thanks John-

When doing this type of form I usually drop the field in detail view and
then move the auto generated label to the header. When moving the label to
the header, it must disassociate itself from the control. The code below,
when placed in those labels, returns not the (previously associated it
seems) control name, but the name of the form.

When I drag a new control to the form, the auto generated label does not
have any events showing in the property tab (Crystal said this earlier, it
makes sense now), so I can't put any code behind the click event of the
associated label. If I move the label to the header of the form, the label
now has events, but since it no longer associated to the control,
parent.name returns the name of the form. Who's on first?

I tried putting the code below directly in the form module of the auto
generated label in the detail part of the form, but that doesn't work. Once
the form is in 'form view' there is no clicking on that label, no matter
what I put in the code J

I will try the tag property and see what I can do with that..

Thanks!

Pam

From: MS_Access_Professionals@yahoogroups.com
[mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of John Viescas
Sent: Tuesday, May 31, 2011 1:58 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: RE: [MS_AccessPros] get control name associated with label

Pam-

The Parent property won't show up in the Properties Window, but it's there
in
code:

strControlName = Me.lblOne.Parent.Name

In 2007, if the controls are in a Layout, then you won't get the warning
about
an unassociated label.

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: MS_Access_Professionals@yahoogroups.com
<mailto:MS_Access_Professionals%40yahoogroups.com>
[mailto:MS_Access_Professionals@yahoogroups.com
<mailto:MS_Access_Professionals%40yahoogroups.com> ] On Behalf Of Pamela
Zimmerman
Sent: Tuesday, May 31, 2011 8:45 PM
To: MS_Access_Professionals@yahoogroups.com
<mailto:MS_Access_Professionals%40yahoogroups.com>
Subject: RE: [MS_AccessPros] get control name associated with label

Hi John-

I believe the labels are associated with the text boxes. There is no small
green corner on the label, or exclamation point saying 'this label is not
associated with a control'. Looking at them I do not however see a 'Parent'
property on the property sheet.

To test, I added a new field, by dragging and dropping from the 'existing
fields' box and I cannot find a 'Parent' property in the automatically
generated label either. I am using Access 2007. Am I missing it?

I will take a look at using the tag property, I can probably make that work.
I would still appreciate getting a handle on the label/parent property issue
if you can help resolve that. It would seem the most common sense way to
work with the control.

Thanks so much for your input John. It is truly appreciated!

Pam

From: MS_Access_Professionals@yahoogroups.com
<mailto:MS_Access_Professionals%40yahoogroups.com>
[mailto:MS_Access_Professionals@yahoogroups.com
<mailto:MS_Access_Professionals%40yahoogroups.com> ] On Behalf Of John
Viescas
Sent: Tuesday, May 31, 2011 12:31 PM
To: MS_Access_Professionals@yahoogroups.com
<mailto:MS_Access_Professionals%40yahoogroups.com>
Subject: RE: [MS_AccessPros] get control name associated with label

Pamela-

When you said "associated," both Crystal and I thought you meant a label
attached to the text box. Typically, if you drag a text box onto a form in
Design view, Access also creates an "associated" label. In fact, that Label
control will have a Parent property that points to the control with which it
is
associated.

It sounds like you have independent labels. In that case, you could put in
the
Tag property of the label the name of the control with which it is
"associated."
You could then use the Tag property in the Click event of the Label control
to
determine which field needs to be sorted.

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: MS_Access_Professionals@yahoogroups.com
<mailto:MS_Access_Professionals%40yahoogroups.com>
<mailto:MS_Access_Professionals%40yahoogroups.com>
[mailto:MS_Access_Professionals@yahoogroups.com
<mailto:MS_Access_Professionals%40yahoogroups.com>
<mailto:MS_Access_Professionals%40yahoogroups.com> ] On Behalf Of Pamela
Zimmerman
Sent: Tuesday, May 31, 2011 5:54 PM
To: MS_Access_Professionals@yahoogroups.com
<mailto:MS_Access_Professionals%40yahoogroups.com>
<mailto:MS_Access_Professionals%40yahoogroups.com>
Subject: RE: [MS_AccessPros] get control name associated with label

Thanks John and Crystal!

I will add a bit. I have a series of forms that display a large amount of
reference table data. Clients need to maintain tables using these forms,
add new, or edit existing records. I have a client that has a large amount
of reference table data. They have requested the ability to sort the data
on various fields by clicking the column headings (which are labels).

The forms are continuous forms with the label in the top section of the form
and the data below in a column, similar in appearance to an excel
spreadsheet. Each form has several columns. It seems intuitive for the
user to click the column heading to sort the data as needed, not as much so
to click the column of data.

Although I could code the click from label using the control name, I don't
especially want to, because I will have to have this in a hundred or so
places and it will be more efficient if I can paste the same thing rather
than edit all of the individual control names in the code.

Crystal, I'm not quite tracking on the notion that a label associated with a
control has no events. I have click event code attached to lblPodNumber
(which is associated with txtPodNumber) and it runs as it is coded (just not
as I want it to).I must be misunderstanding something here.it's getting
late.

All I really want, is on the click of the label, move the focus to that
label's associated control. This would then make the desired control the
active control, and then the code would work. Is this possible??

From: MS_Access_Professionals@yahoogroups.com
<mailto:MS_Access_Professionals%40yahoogroups.com>
<mailto:MS_Access_Professionals%40yahoogroups.com>
[mailto:MS_Access_Professionals@yahoogroups.com
<mailto:MS_Access_Professionals%40yahoogroups.com>
<mailto:MS_Access_Professionals%40yahoogroups.com> ] On Behalf Of Crystal
Sent: Friday, May 27, 2011 2:15 PM
To: MS_Access_Professionals@yahoogroups.com
<mailto:MS_Access_Professionals%40yahoogroups.com>
<mailto:MS_Access_Professionals%40yahoogroups.com>
Subject: 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
>
>
>

[Non-text portions of this message have been removed]

------------------------------------

Yahoo! Groups Links

[Non-text portions of this message have been removed]

------------------------------------

Yahoo! Groups Links

[Non-text portions of this message have been removed]

------------------------------------

Yahoo! Groups Links

__._,_.___
Recent Activity:
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.


Find useful articles and helpful tips on living with Fibromyalgia. Visit the Fibromyalgia Zone today!

.

__,_._,___

Tidak ada komentar:

Posting Komentar