Solved Labels without Events

KitaYama

Well-known member
Local time
Today, 10:42
Joined
Jan 6, 2022
Messages
2,010
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

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
 
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.
 
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.
 
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:
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.
 
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")
 
@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.
 
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

Back
Top Bottom