Problem creating VBA controls at runtime

D

Dootje

On the 'net I found several examples on how to create VBA controls at
runtime. I am trying to get the examples working, but I keep running into an
error at the point where I call the Controls.Add method. VBA (version 6.0
shipped with Access 2000 in this case) invariably tells me it does not know
this method. I have tried referencing to a number of libraries, VBA
extensions 5.3 among others, but the problem persists. What am I missing
here?!? Thanks in advance to those who bother to reply.

Dootje
(e-mail address removed)
 
C

Cindy M -WordMVP-

Hi Dootje,

I'm afraid you don't supply enough information. What kinds of Controls? You
can't simply type controls.Add; something has to precede Controls. Like
CommandBars("Name"). or Me.
On the 'net I found several examples on how to create VBA controls at
runtime. I am trying to get the examples working, but I keep running into an
error at the point where I call the Controls.Add method. VBA (version 6.0
shipped with Access 2000 in this case) invariably tells me it does not know
this method. I have tried referencing to a number of libraries, VBA
extensions 5.3 among others, but the problem persists. What am I missing
here?!?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
D

Dootje

Cindy M -WordMVP- said:
Hi Dootje,

I'm afraid you don't supply enough information. What kinds of Controls? You
can't simply type controls.Add; something has to precede Controls. Like
CommandBars("Name"). or Me.


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)


This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)

Cindy,

Thanks for the reply. Here's more info: A user has to enter multiple items
(at least one) that are selected from a predefined table. I want to use a
variable number of comboboxes for this. The reason I don't want to use a
simple
listbox with MultiSelect set to True is that, for each
selected item, the user has to enter two more properties in two textboxes.
At the start, I show one combobox. As soon as an item is selected in the
first combobox, I want the two textboxes to appear, plus a new combobox
below the first one so the user can choose another item. As soon as a
selection is made in the second combobox, two more textboxes plus a third
combobox need to appear, and so on.

Since the number of items the user is going to enter is unknown, I thought
it would be elegant to create the appearing textboxes and comboboxes at
runtime. Of course I could also do this with hidden comboboxes, but then I
would have to define their maximum number at compile time, which I don't
want to do.

I Googled an example that says something like:

<snip>
Public Sub WhatToDoAfterASelectionIsMade(SomeVariable as Long)
Dim MyNewCombobox as ComboBox
...
Set MyNewCombobox = Forms.Controls.Add("VB.Combobox","NewBoxName", Me)
...
End Sub
<\snip>

But I get the error message 'Object does not support this property or
method'
(freely translated from Dutch) at the line starting with Set. And indeed the
object library shows nothing of the sort, so that makes sense. Question is,
how
do I get this method into my project? Or is there another way to achieve
want I
want to do?

Is this enough info for you? I hope you can make chocolate of it (liberally
translated Dutch expression - shouldn't be too hard for a Swiss).

Cheers,

Dootje
(e-mail address removed)
 

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