Adding Text Boxes to form when Button is clicked.

dazmelb
NewLounger
Posts: 2
Joined: 07 Aug 2013, 02:52

Adding Text Boxes to form when Button is clicked.

Post by dazmelb »

Hi,

I am trying to add text boxes to my MS Access DB GUI form using VBA so that when a record is added to a table via an add button a series of text boxes will be created based on the the data in the db table.
I saw a similar question being asked in the following link:
http://social.msdn.microsoft.com/Forums ... access-vba

But when I tried to insert that code into my form and run the GUI I received an error
"Run-time error '29054':

Microsoft Access can't add, rename, or delete the control(s) you requested"

I was wondering if you can help?

Thanks

Dazmelb!

User avatar
HansV
Administrator
Posts: 78481
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Adding Text Boxes to form when Button is clicked.

Post by HansV »

Welcome to Eileen's Lounge!

What do you mean by "insert that code into my form"? The code from my reply in that thread is not intended to be run from the form itself, but from outside it, for example from another form.

Have you read the warnings in that thread about the serious limitations of creating controls at runtime?
Best wishes,
Hans

dazmelb
NewLounger
Posts: 2
Joined: 07 Aug 2013, 02:52

Re: Adding Text Boxes to form when Button is clicked.

Post by dazmelb »

hey hans,

I ran it from the form itself. Yes I have read the limitations. If I have a subform within the form can have the text boxes appear in the subform and run the code from the form itself?

I am trying to have text boxes appear on the same screen.

Regards

Dazmelb

User avatar
HansV
Administrator
Posts: 78481
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Adding Text Boxes to form when Button is clicked.

Post by HansV »

No, you can't run the code from the main form. You cannot open a subform in design view while its main form is open in form view.

An alternative would be to create a number of text boxes on the subform in advance, and to set their Visible property to No.
You can use code to set Visible for specific text boxes to Yes dynamically in runtime, and you can also set the Control Source of text boxes in runtime
Best wishes,
Hans