Dynamically Create Textboxes, and Form Scrolling?

Posted on 2004-11-24
Last Modified: 2010-05-02
I have a program that asks for the number of transaction that happened. I would like it to be able to handle most situtations, but I don't know how many input boxes to have by default. More than likely, it will never be more than 10. I found a form scrolling sample and added rows of text boxes. I then made the text boxes invisible and changed the form scrolling thing to only check visible controls. That way, when the text boxes are invisible, the scroll bar goes away. The problem is, with many text boxes, the scrolling is slow and choppy. Some controls scroll up faster than others, so the form gets distorted a little. Is there a way to dynamically create text boxes when they are needed or is there a better way to get as many as I need?
Question by:Greggory
    LVL 7

    Expert Comment

    Starting in VB6 you can add controls at runtim with this code. Pretty simple

    Private WithEvents txtNew As VB.TextBox

    Private Sub cmdNewUpDown_Click()

      Set txtNew = Controls.Add("VB.TextBox", "TextDynamic")
      txtNew.Text = "New TextBox"
      txtNew.Visible = True
    End Sub

    Private Sub txtNew_KeyPress(KeyAscii As Integer)
      KeyAscii = KeyAscii - 1
    End Sub
    LVL 28

    Accepted Solution

    If you add 1 textbox and give it an index of 0 you can use its position to add new textboxes

    Dim i As Integer

    Private Sub Form_Load()
    i = 1
    End Sub

    Private Sub Command1_Click()
    Load Text1(i)
    Text1(i).Top = Text1(i - 1).Top + Text1(i - 1).Height
    Text1(i).Visible = True
    i = i + 1
    End Sub
    LVL 7

    Expert Comment

    As a sidenote you would probably be better off using a FlexGrid control.
    Then you don't have to worry until i think 65K entries.... Never hit the limitation using it.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    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…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now