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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Controls

Status
Not open for further replies.

Elena

Technical User
Oct 20, 2000
112
US
Hi,

This one is troubling. I am trying to add controls dynamically, based on user entry and on information from a database. I want to add a frame(1 or more, depends on user entry) and then inside the frame have one or more command buttons and text boxes. I can create the frame and the command button, but I can't figure out how to set the frame as the container for the command button.

Here is the code I have so far:


Dim cmdButton As VB.CommandButton
Dim frameFrame As VB.Frame

Set frameFrame = Form1.Controls.Add("vb.frame", "frame1")
With frameFrame
.Visible = True
.Top = 120
.Left = 120
.Height = 1500
.Width = 1500
End With
Set cmdButton = Form1.Controls.Add VB.commandbutton", "cmdCommand")
Set cmdButton.Container = frameFrame 'This is where the problem seems to be.

cmdButton.Visible = True
cmdButton.Left = 120
cmdButton.Top = 120
cmdButton.Height = 400
cmdButton.Width = 600


Any suggestions.

Thanks,
 
I don't see a problem that line it's the line above it that contains syntax errors. Also if you want to be able to capture events from these new controls you'll need to declare them WithEvents.

Private WithEvents cmdButton As VB.CommandButton
Private WithEvents frameFrame As VB.Frame

Private Sub Form_Load()
Set frameFrame = Form1.Controls.Add("vb.frame", "frame1")
With frameFrame
.Visible = True
.Top = 120
.Left = 120
.Height = 1500
.Width = 1500
End With
Set cmdButton = Form1.Controls.Add("VB.commandbutton", "cmdCommand")
Set cmdButton.Container = frameFrame
cmdButton.Visible = True
cmdButton.Left = 120
cmdButton.Top = 120
cmdButton.Height = 400
cmdButton.Width = 600

End Sub
 
DrJavaJoe,

Thanks for the input. I did get that part working. I have another question, however. If I declare the command button with events, and then I create several different command buttons, how do I respond to the events from the individual command buttons? What I have is a database that will tell the program which sets of files it needs. Each set of files will be sorted into their respective OSes (frames). The program goes out and gets the requirements and creates one command button and one text box for each set of files it needs. Then I want the user to be able to click on the command button and browse the file system to find the location of the files to test. That location will be placed into the text box. I have this function already, but I am not sure how to apply it dynamically.

Any advice would be appreciated.

Thanks,
Elena
 
In that case I would add the first textbox to the form at design time, set it's visible property to False and it's index to 0. When I needed the first textbox I would make this one visible and place it where I wanted. Then with each additional textbox I would use the load command such as:

Load Text1(NewIndex).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top