Solved Labels without Events (2 Viewers)

KitaYama

Well-known member
Local time
Today, 15:03
Joined
Jan 6, 2022
Messages
1,541
I've seen several labels in some forms that can not accept events.
In design view of mentioned forms, if I select the label, the Events tab of their property sheet is blank

2023-07-14_08-13-19.png


I first thought they may not be labels. But immediate window shows 100 as their control type. So they are definitely labels.
Selection type of the property sheet says Label too.

Code:
    For Each c In Me.Controls
        Debug.Print c.Name & " -->" & c.ControlType
    Next

The form is not corrupted. It's perfect and has been running for several years.

Does anyone have any idea what causes this or know how to add codes to their events procedures?

Thank you.
 

Attachments

  • Test.accdb
    396 KB · Views: 53

isladogs

MVP / VIP
Local time
Today, 07:03
Joined
Jan 14, 2017
Messages
18,221
Unattached labels have 5 events that can be programmed
Attached labels have no events of their own. They are an integral part of the control that are attached to e.g. textbox, command button.
The events available are those for the control itself
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:03
Joined
Oct 29, 2018
Messages
21,473
I agree with the above. This is how in the old Switchboard, the user is able to click on either the button or the menu description (label) to initiate that option.
 

KitaYama

Well-known member
Local time
Today, 15:03
Joined
Jan 6, 2022
Messages
1,541
Unattached labels have 5 events that can be programmed
Attached labels have no events of their own. They are an integral part of the control that are attached to e.g. textbox, command button.
The events available are those for the control itself
Seems that no matter how much I learn about Access, there's still room to be surprised more.
Never heard of it, but it seems that's the case.


I found this via Google.
I never bothered to check the documentation. My bad. I thought I know enough. Apparently I don't. It's clearly stated the events only show for unattached labels.


Million thanks for the lesson.
 

KitaYama

Well-known member
Local time
Today, 15:03
Joined
Jan 6, 2022
Messages
1,541
I agree with the above. This is how in the old Switchboard, the user is able to click on either the button or the menu description (label) to initiate that option.
I have never used those type of switchboard and I have no idea why a button needs a label.
But in terms of normal forms, I don't understand what would go wrong if an attached label to a textbox or another control could accept an event too.
For example in case of a label attached to a textbox, it could activate the textbox and meanwhile run a procedure.
But it's the way it is. And I can live with it. I'll detach the label.

Million thanks for solving the puzzle.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:03
Joined
Feb 28, 2001
Messages
27,186
But in terms of normal forms, I don't understand what would go wrong if an attached label to a textbox or another control could accept an event too.

Mostly because in structural terms, an associated label is a child of the control to which it is associated. A free-standing label, however, is just another control. If the label is the child of the associated control then all events belong to the parent.

This is a pain in the toches when trying to find an arbitrary control's label on a form or report. The only way I ever found that didn't involve some sort of trick with naming conventions was to do a "For Each ctl In Me.Controls" loop looking for the label whose .Parent pointed to the required control.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:03
Joined
May 21, 2018
Messages
8,529
This is a pain in the toches when trying to find an arbitrary control's label on a form or report
You will have to explain that, given there are two ways to do it?
Code:
msgbox "SomeControl's label name is: " & me.someControl.controls(0).name
msgbox "SomeControl's label name is: " & me.somecontrol.properties("labelName")
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:03
Joined
Feb 28, 2001
Messages
27,186
@MajP - at the time I was trying to do this, I don't recall finding the .LabelName property. This was in the first Access database I ever did for the Navy, one that I inherited, and it was a VERY low version number of Access. Nor was I as experienced as I am now. As I said (and please remember to include "at the time" when considering my response), the only way I found was that loop. If there are more (and easier) ways to do this now, then great! But when I asked on the forum at that time, the only answer I got was the loop. My, how times have changed.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:03
Joined
May 21, 2018
Messages
8,529
I believe the Label Name property is somewhat new; I do not remember always seeing it in the properties window. You always could do it with Controls(0).
 

Users who are viewing this thread

Top Bottom