Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access VBA - Dynamically Add Controls to Form

Status
Not open for further replies.

rlievesley

Technical User
Jun 7, 2005
2
GB
Hi,

I'm starting to learn vba in access, and wonder if anybody can help me with this question.

I have previously created some VBA code in excel which dynamically adds controls to an existing form.
I want to use similar code in Access, but the Form.Controls.Add method I used in Excel VBA is not supported.

For example, in Excel, the code I used to add a label called lblGEIName to UserForm1 was:

dim theGEINameLabel

Set theGEINameLabel = UserForm1.Controls.Add("Forms.Label.1", "lblGEIName")
With theGEINameLabel
.Left = 50
.Top = 100
.Caption = "GEI Name"
End With

UserForm1.Show

This code was in a sub in a module, and when called would display the form with the label.

When I try the same code in Access VBA, I get a "Complile Error, Method or Data Member Not Found" on the Add section of UserForm1.Controls.Add

Does anybody know how I can get to dynmically add controls to a form in access like this?

Many thanks for any help

Rob
 
In the Access VBA help file have a look at the CreateControl method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Great, thanks PH. Sorry if it seemed a simple question, all the references I'd been able to find were for the controls.add method. CreateControl looks to be exactly what I need, that's really useful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top