• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1017
  • Last Modified:

Access 2003 Detatch/Attach a Label to a TextBox Programatically

Anybody know how to do it?  To attach via the keyboard, click on the label, Ctl+X, click on the textbox, Ctl+C.  Same thing in reverse to detatch, but you have to move the label as it re-appears following the Ctl+C.  
0
GRayL
Asked:
GRayL
  • 6
  • 4
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Hi Ray

Nope.  I immediately kill all labels associated with whatever other control I just created, and then create a separate label.
That way, I can align/resize the labels and controls independant of each other.
0
 
GRayLAuthor Commented:
I found this out.  You can refer to a label named lblAny attached to a textbox named tbxAny all on a form named frmAny using:

Forms!frmAny!tbxAny.Controls("lblAny")

When a control does not have an associated label, Forms!frmAny!tbxAny.Controls.Count = 0

If you enter that line in a code window, Intellisense will give you a drop down with 21 elements, one of which is Properties which has 41 values when the label is attached to a control, 49 when it is by itself.  Nothing in either list seems to tie it to the control it may be bound to.

I found out how it remove a control from a form, but this disassociation is the part that has me perplexed - there has to be a way.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
I swear there is an 'attached' (or similar name) property for either a text box or label ... but, I can't find it.

mx
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
gRay ... open the Object Browser, select Access in the dd list, then scroll down to TextBox.

On the right, you will see AddColon, AutoLabel ...etc.  These are what I was thinking about ...


For example ... in Help:

AutoLabel Property
See AlsoApplies ToExampleSpecificsThe AutoLabel property specifies whether labels are automatically created and attached to new controls. Read/write Boolean.

expression.AutoLabel
expression    Required. An expression that returns one of the objects in the Applies To list.

Setting

The AutoLabel property uses the following settings.

Setting Description
Yes A label is attached to new controls.
No A label isn't attached to new controls.

You can set these properties only by using a control's default control style or the DefaultControl method in Visual Basic.

Remarks

Changes to the default control style setting affect only controls created on the current form or report. To change the default control style for all new forms or reports that you create without using a Microsoft Access wizard, see Specify a new template for forms and reports.

0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
more:

AddColon Property
See AlsoApplies ToExampleSpecificsThe AddColon property specifies whether a colon follows the text in labels for new controls.
Read/write Boolean.

expression.AddColon
expression    Required. An expression that returns one of the objects in the Applies To list.

Setting
The AddColon property uses the following settings.

Setting Description
Yes A colon follows the text in labels for new controls.
No A colon doesn't follow the text in labels for new controls.

You can set these properties only by using a control's default control style or the DefaultControl method in Visual Basic.

Remarks
Changes to the default control style setting affect only controls created on the current form or report. To change the default control style for all new forms or reports that you create without using a Microsoft Access wizard, see Specify a new template for forms and reports.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Also LabelX and LabelY.

Type these in the Immediate window, double click to highlight ... and hit F1 >>> right to Help File info.

mx
0
 
GRayLAuthor Commented:
Thanks Jim, I was all over the map on this one and it looks like 'Nope' is the answer.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
?

Disassociating every label seems like a waste.   Because, if you need to make a text box Not Visible for example  (Me.Text1.Visible = False), then you need to add an extra line of code for the related label also.  If they are attached, you do not.

mx
0
 
GRayLAuthor Commented:
While snooping around another Access forum I came across this;

application.CreateControl "frmAny",acLabel,acDetail,"tbxAny","",1440,1080,1000,300

This command creates a control with default name Labeln, on form 'frmAny', associated with parent 'tbxAny',unbound to any field (""), at these twip locations.  

A similar application.DeleteControl will remove the control.

Jim, I wan't my poinks back!
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Well yeah, but you didn't say Create ... you said 'Detatch/Attach' ...

mx
0
 
GRayLAuthor Commented:
Right your are.  Can't even read my own question.  Still snooping.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now