Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 24th, 2011, 09:08 PM
Registered User
 
Join Date: Mar 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic TextBox Name from Form

Hi,
I am pretty new to VBA and struggling to work this out.

I have a form used to enter data into a table. The data consists of one promotion & the promotion may have multiple products.
I have set up 10 separate textboxes to enter the ten different products (there may be even more products), name ProdNo1, ProdNo2 etc.

My question is, do I have to load all 10 Product TextBoxes separately, or is there some way to loop through the TextBoxes and perhaps have the name as a variable?

I am thinking something like this (somewhat like the INDIRECT function):

NoOfProducts = 1
ProductNumber = "ProdNo" & NoOfProducts

But it errors on the use of:
UserForm1.ProductNumber.Value

The ProductName appears to contain the correct data (ie ProdNo1), but it doesn't like it when used as part of the Object Name.

Does anyone know how to create a dynamic Object name, or alternatively a way to loop through adding the textboxes without having to code each one separately?

Thanks in advance for help,
janie
 
Old March 24th, 2011, 09:16 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 171
Thanks: 0
Thanked 14 Times in 14 Posts
Default

Dunno if it will help you or not, but if you type in userform1 (or whatever the name of your form is, intellisense pops up this:
Code:
userform1.Controls.Add(brstrProgIDasString, Name,Visible) as TextBox
So I'm guessing you could probably set up a looping structure to dynamically add textboxes based on some form control event. Hope that helps, good luck





Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamic textbox creation badamsreekar ASP.NET 2.0 Professional 1 July 26th, 2007 10:40 AM
help writing dynamic form data to dynamic table ublend SQL Server ASP 1 June 1st, 2007 08:09 AM
help writing dynamic form data to dynamic table ublend Classic ASP Professional 1 June 1st, 2007 08:08 AM
Dynamic Textbox viprsh81 ASP.NET 2.0 Professional 2 July 20th, 2006 04:46 AM
Dynamic TextBox stu9820 ASP.NET 1.0 and 1.1 Basics 2 February 4th, 2004 04:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.