0
votes

I have a form where Client Info will be displayed. What I did is I created a user control with a bunch of textboxes lined up next to each other for Fname, Lname, Dob, SSN, etc. On the form itself, I created a copy of the user control but with labels to display the information that I'll in the USER CONTROL itself. So on FORM_LOAD, I'm pulling data from the server and I need it to add just as many USER controls as I have Clients in the database. The problem I'm seeing is, each time I add a control with this statement

Dim myCtl As Control
Set myCtl = Controls.Add("Project1.UCclient", "MyCtl", frmClientUC)
        myCtl.Visible = True

....the user controls name gets incremented by one. So the first one I added on the form is ucclient1, then if i add another its ucclient2 and so on. Additionally, i loaded one of the USER CONTROLS with data (just to make sure it worked), I had to specify which ucclient I was referencing. So for the first one that I loaded I SELECTED data from SQL-SERVER then did this...

ucclient1.fldFirstName =RS!FirstName
ucclient1.fldLastName = RS!LastName

...and so forth for all the other fields. Because I have to specify what user control form I'm putting the data into, is there a way for it to increment it by itself? Possibly looping? I'm a newbie in VB6 and I'm just having a difficult time makign this work harmoniously without a 1000 lines of code.

2
Please read How do I ask a good question?. This is not a question, let alone a good one.C-Pound Guru

2 Answers

0
votes

You would do it the same way that you would any control. Put one control on the form in design mode. Set its index property to 0 to make it a control array. (If you have a context where you don't want any controls, then make it invisible and then make it visible when you need it.) Then add more controls as you need them, setting the Top and Left properties to position them on the page.

Here is the doc for adding a control to a control array at runtime.

0
votes

Ok. I've found out a new way. It works well. + At form1, add a new user control (U1). + Copy code U2 (The User control of another project) into U1. Save it with the same name. + Close U1 + At Form1, open ToolBox and click U1. There is an error message apear and you'll see the name of control missing (missing name). + Open the propertice of U2. Choose the missing name to see kind of control. + Open U1 and add the control and name it as the same name (missing name). + Return Form1 and click U1 in Toolbox to add control U1. + Make propertice U1 as same as U2. sorry about my English.