Creating labels using VBA

M

MacNews

Hi

Using Access XP (2002), I have a form where I move and resize label fields
in a scheduler application. Currently, I have created 20 invisible labels
on the form then as required, I alter the parameters (left, top, width,
height, colours) to suit the requirement of the data for the particular
date.

While my method works, is there a way where a label can be created using VBA
code ? This would make the application slicker.

Thanks

Peter
 
A

Arvin Meyer [MVP]

I think that you have the best method. To add controls at runtime, you need
to open the form in design view. You can, however move and show or hide
controls at runtime.

Here's some code that will add a label control to the Header of a from named
Form1:

Sub AddLabel()
Dim frm As Form
Dim lbl As Label

DoCmd.OpenForm "Form1", acDesign
Set frm = Forms("form1")
frm.Section(acHeader).Visible = True

Set lbl = CreateControl(frm.Name, acLabel, acHeader, vbNullString,
vbNullString, 100, 100, 1000, 230)

lbl.Caption = "Test Header"

DoCmd.Close acForm, "Form1", acSaveYes
Set lbl = Nothing
Set frm = Nothing

End Sub
 
F

fredg

Hi

Using Access XP (2002), I have a form where I move and resize label fields
in a scheduler application. Currently, I have created 20 invisible labels
on the form then as required, I alter the parameters (left, top, width,
height, colours) to suit the requirement of the data for the particular
date.

While my method works, is there a way where a label can be created using VBA
code ? This would make the application slicker.

Thanks

Peter

The problem with your adding labels using VBA is that there is a limit
of 754 controls (even if you delete some) you can add to a form over
it's lifetime .

See Access Help + Specification + Access specifications + Forms and
Reports.
 
M

MacNews

Hi Allen
Thanks - was of help. We're using the same idea but the demo did give me a
different approach.

Peter - also from Perth, Western Australia - small world.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top