[AccessD] Programmatically dissociate label from its parent control

Bill Benson bensonforums at gmail.com
Mon Jul 27 13:59:44 CDT 2015


John, it is not something I would have wanted to do at runtime - not sure
what sense that would make. It is something I would want to run from a
standard module while a freshly created form is open in design view, like
so:

Sub removelabels()
Dim ctrl As Control
For Each ctrl In Screen.ActiveForm.Controls
    If TypeName(ctrl) = "Label" Then
        On Error Resume Next
        ctrl.Controls(0) = Null
        If Err.Number <> 0 Then Debug.Print Err.Description
    End If
Next
End Sub

Anyways, it does not work in design view at least, I am getting this error
"You entered an expression that has an invalid reference to the property
Controls."


On Mon, Jul 27, 2015 at 1:07 PM, John W. Colby <jwcolby at gmail.com> wrote:

> Each control has a .Controls collection, as does the form itself. The
> label is always Controls(0), the "zeroth" item in the collection.
>
>
> You have to get a pointer to the current form.
>
> dim ctl as control
> So for each ctl in frm.Controls
>     ctl.controls(0) = null
> next ctl
>
> I don't remember whether this can be done at run time or whether you have
> to do this in design mode and save the form.
>
> I THINK it can be done at runtime.
>
> John W. Colby
>
>
> On 7/27/2015 12:35 PM, Bill Benson wrote:
>
>> Anyone know a way to do this? I almost never like labels clinging to
>> controls when the parent controls are added. This happens en masse when
>> dragging fields onto a fresh form, and I have to select the labels one by
>> one and cut/paste, reposition them, which is a nuissance.
>>
>> If there is a way to shut off the label feature entirely that might be an
>> adequate half-measure, but what I would really prefer is a way to loop
>> controls and dissociate them from the parent controls they may be clinging
>> to without having to eliminate them entirely (were that even possible).
>>
>> Bill
>>
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>


More information about the AccessD mailing list