creating text boxes in code

Posted on 2003-03-08
Medium Priority
Last Modified: 2010-05-01
im sure this is easy, if it isn't please advise me and i will regrade it.

I have two forms,  "form 1" contains a list box, with a variable number of items in it.
I need to create labels and list boxes for each of those items in "form 2" when i click on the command button in "form 1".  

Please help, none of my books give me the commands, and i have scrolled through about 5000 answers on here.
Question by:irishboyx
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 70

Expert Comment

by:Éric Moreau
ID: 8093866

Expert Comment

ID: 8093957

An easier way to add controls to a form dynamically is to use a control array.

It does require a little coding though:

1) add a prototype control to your form
2) set the index property to 0 (zero)
3) Code the evente that you need to use (Use the Index parameter to identify the control that caused the event)

When you need to add a new control then you

1) Load ControlName(New_Index_Number)
' the indexnumber of the control must not currently exist
2) Position the control where you want it
3) set the visiblew property to true

You can now use all the events that you created for the
control with the zero index.

Note that the first parameter is the index number of the control that caused the event.

To remove the controls you use the UNLOAD function

Good Luck,

Expert Comment

ID: 8094191
Step 1:  Place a Label and TextBox in the Form2
Step 2:  Set 0 in the Index Property of those Lable and TextBox controls
Step 3:  Write the following code in the Command Button Click event of Form1

Private Sub Command1_Click()
    Dim lngCnt as Long

    With Form2
        .Label1(0).Caption = "List 1"
        .Text1(0).Text = List1.List(0)
        For lngCnt = 1 to List1.ListCount - 1
             Load .Label1(lngCnt)
             .Label1(lngCnt).Caption = "List " & lngCnt + 1
             .Label1(lngCnt).Move .Label1(lngCnt-1).Top + .Label1(lngCnt-1).Height + 120
             .Label1(lngCnt).Visible = True
             Load .Text1(lngCnt)
             .Text1(lngCnt).Text = List1.List(lngCnt)
             .Text1(lngCnt).Move .Text1(lngCnt-1).Top + .Text1(lngCnt-1).Height + 120
             .Text1(lngCnt).Visible = True
    End With
End Sub
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 8900474
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
LVL 49

Expert Comment

ID: 9074465
irishboyx, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

DanRollins -- EE database cleanup volunteer
LVL 70

Expert Comment

by:Éric Moreau
ID: 9075313
My recommandation: split between emoreau and SSSoftware

Accepted Solution

YensidMod earned 0 total points
ID: 9165932
Without feedback from asker, it is hard to tell who is correct. Question is PAQ'd and no points refunded.

Community Support Moderator @Experts Exchange
LVL 70

Expert Comment

by:Éric Moreau
ID: 9166424
Why didn't you follow my recommandation?

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question