create textbox programmatically

M

mike

Hi all,

I'm trying to create a text box programmatically andI'm
having trouble.

In Form1(the name of my form), I have a command button.
When the command button is click. It automatically create
a text box within the form. But I'm getting error.

Here is the code.

Dim ctr As Control

Set ctr = CreateControl(Form1, acTextBox, acDetail)

The error is: Access can't find the form name refer. The
form name is Form1 which I have provided.Any suggetion on
what I did wrong?

thanks for the help.

mike
 
J

JSand42737

"mike" said:
Hi all,

I'm trying to create a text box programmatically andI'm
having trouble.

In Form1(the name of my form), I have a command button.
When the command button is click. It automatically create
a text box within the form. But I'm getting error.

Here is the code.

Dim ctr As Control

Set ctr = CreateControl(Form1, acTextBox, acDetail)

The error is: Access can't find the form name refer. The
form name is Form1 which I have provided.Any suggetion on
what I did wrong?

thanks for the help.

mike

Mike

There are two problems with this, one minor and one major.

The first, minor one, is that when you refer to a form, or any other object,
you need to wrap it in quotes, so you would need to use "Form1". Alternatively,
you coulc use Me to refer to the current form.

The second, major problem, is that you cannot create controls on a form unless
it is open in design mode. And since you run your code from the form view, this
code is never going to work.

If you need extra controls on a form, the trick is to create them manually, and
then you can manipulate them as required (move the position, set the
visibility, etc).
 
M

mike

Thanks.
-----Original Message-----
Mike

There are two problems with this, one minor and one major.

The first, minor one, is that when you refer to a form, or any other object,
you need to wrap it in quotes, so you would need to use "Form1". Alternatively,
you coulc use Me to refer to the current form.

The second, major problem, is that you cannot create controls on a form unless
it is open in design mode. And since you run your code from the form view, this
code is never going to work.

If you need extra controls on a form, the trick is to create them manually, and
then you can manipulate them as required (move the position, set the
visibility, etc).




--

Jon

www.applecore99.com - Access Tips and Tricks

.
 

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