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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is dynamic control creation available in VBA? 1

Status
Not open for further replies.

bkatz

IS-IT--Management
Jun 16, 2002
7
US
Could someone confirm what I think is the case... that dynamic control creation is NOT available in VBA (specifically, MS Access)?

If I am wrong, and it is available, would someone be so kind as to give a simple simple example, say creating a command button at load time?

example in VB...

' (i have a command button already called "cmdTests", with index 0, implying it's part of an array).
' the following will create two command buttons on a VB form.

Load cmdTests(1)
Load cmdTests(2)

cmdTests(1).Top = 100
cmdTests(1).Left = 100
cmdTests(1).Caption = "Test 01"
cmdTests(1).Visible = True
cmdTests(2).Top = 800
cmdTests(2).Left = 100
cmdTests(2).Caption = "Test 02"
cmdTests(2).Visible = True

 
Hi

See the command CreateControl() in help, it will allow you to create a control at run time, note you must open the form on which the control is to be created in design view, see the DoCmd.OpenForm command in help for how to do this Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
thank you so much for your answer. i think because of the complexities involved (ex. you have to open the form in design view, it seems really tricky to get a new control to respond to an event, etc. etc.) VBA control creation isn't really appropriate at run time. But at least now I have a start if I want to study it further... gracias.

 
By the way, if you ever want to release your database as an .mde file, I imagine you will have trouble opening your form in design view.
 
Well, you could have a bunch of controls with no code behind them, and set their visible to false.

See the switchboard created by the switchboard manager for an example...... Tyrone Lumley
augerinn@gte.net


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top