Dymically add text box to form in Word Macro

J

JUICE

Hi,
I was wondering if anyone could help. I am getting an "object required"
error on the following line of code:

Set ctlText = Controls.Add("VB.TextBox", "ctlText1")

I am initialising like so in the class module:

Dim WithEvents ctlText As VB.TextBox
 
J

Jezebel

The keyword 'Controls' is defined in both the Office and Forms libraries;
and the Office library normally takes precedence in the references list. So
the 'object required' -- in this case -- is the commandbar that owns the
controls collection.

Try: Me.Controls.Add(...)
 
J

JUICE

Hi,
Thanks for your reply. I have tried
Set ctlText = Me.Controls.Add("VB.TextBox", "ctlText1")

and it has generated the error "invalid use of me keyword"
 
J

Jezebel

Is the line of code within a form? If not, instead of Me, you want a
reference to the form.
 
S

Steve Macleod

ok, thanks for this.
I have attempted to use the form name:
genScriptfrm.Controls.Add("VB.TextBox", "ctlText1")
although this generates an "invalid class string" error.
The code is within a private sub. I am unsure if I must pass a
reference to the form in through the main sub that starts when the
macro is run.

Can anyone advise?

Many, thanks.
 

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