PDA

View Full Version : how to load textbox?



maryam
03-06-2007, 10:48 PM
How can I load textboxes for i=1 to listbox.listcount?
I want the same number of textboxes as the number of items in the list box.

JimmyTheHand
03-07-2007, 01:25 AM
Hi Mary :hi:

See the attachment for sample and code about how to create textboxes in runtime. Additional info to code line
.Name = "TxtBoxForListBox" & CStr(i) 'it's important to name the control follows:

If you don't specify the name of the new textbox, Excel gives a default name, just like in design time. However, you don't know what the name is, and to refer to the textbox in the future, you need the name. So it's very important that you control the names of the textboxes to be created.


Regards,

Jimmy

moa
03-07-2007, 03:49 AM
maryam, you could always create the textboxes and have them sitting on your form invisible then make them visible when necessary.

maryam
03-08-2007, 12:58 AM
Hi Jimmy,
I tried this, but in my form I have multiPage and I don't know how to change:
Set Ctrl = UserForm1.Controls.Add("Forms.TextBox.1")

what does Cstr(i) mean in the name?



many thanks,
Mary

Bob Phillips
03-08-2007, 01:50 AM
I am not a fan of creating controls on the fly (how will you capture the data etc.?), but this adds a textbox to page2 of the multipage



Dim ctrl As Object
Set ctrl = Me.MultiPage1(1).Controls.Add("Forms.TextBox.1")

maryam
03-08-2007, 03:53 AM
but Jimmy is giving name to them.
the textboxes will be manupulated only if sheet1 is the active sheet. How can we manupulate them even if active sheet is another sheet?

Bob Phillips
03-08-2007, 07:41 AM
So what? It is still not known to the form at runtime.

JimmyTheHand
03-08-2007, 08:33 AM
So what? It is still not known to the form at runtime.
I'm not sure, Bob, what you mean by "capturing data", but you can certainly access the text property of runtime created textboxes. See te attached example. Use the button called "Query textbox", and input a number from 1 to 10.

Jimmy

Bob Phillips
03-08-2007, 08:39 AM
Sure, but you there is no event code, such as Enter, Exit, etc.

JimmyTheHand
03-08-2007, 08:57 AM
Yeah, that's right. Invisible controls, as Moa suggested, are better in this aspect (and some more). Except when it's unknown in advance, how many and what kinds of controls would actually be needed.

Bob Phillips
03-08-2007, 10:22 AM
My view entirely. Easier to add them at design and hide/unhide as required.