Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically Generate

Status
Not open for further replies.

JPBURBE

Programmer
Jun 12, 2001
37
CA
Is there any way under a command button, to have a form generated with textboxes & labels, etc? I am planning on using variables to pass the info for the labels.....any ideas anyone? I know i could do it manually but would prefer to have it generated for me......Thanks in advance
 
There are two ways you can do this - depending upon your vb version. With versions 5 and below (I believe...someone correct me if I'm wrong here) - you have to create at least 1 instance of the control during design. Make sure you set the Index to 0 - then you can use:

Code:
Load Text1(1)
Text1(1).Visible = True

etc...

Make sure you adjust the top, left, height, and width properties as necessary. This clones the existing control - with the exception of the visible and index properties -and it will be indentical to it in every other respect.

Beginning with 6.0, you can create them on the fly:

Code:
Dim txtExampleText1 as Control
set txtExampleText1 = frmExampleForm1.Controls.Add("VB.TextBox", "Text1", frmExampleForm1)
txtExampleText1.Visible = True
txtExampleText1.Top = 100
etc...

Notice that when setting the properties you still have to refer to it with the object variable name you dim-ed as the control.

All depends upon which version you have and how lazy you are ;-)

Do a search for "add controls during runtime visual basic" on the web and you should get some more detailed docs.

Hope this helps
J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top