Dynamic Control Creation

Posted on 2006-04-19
Last Modified: 2010-05-01
I am using this code to create x numer of command buttons - I will add positioning etc

for i = 1 to x
 load CmdBut(i)
 CmdBut(i).enabled = 1
next i

But how do I 'click' the newly created button?

Private Sub Command(i)_Click()

'Do something

End Sub

Question by:NessieB
    LVL 85

    Accepted Solution

    The code for the click handler would be:

        Private Sub CmdBut_Click(Index As Integer)

        End Sub

    So if you wanted to click the new button it would be:

        Call CmdBut_Click(i)


    Author Comment

    Really??? that simple!

    so if I knew I would have a maximum of 100 buttons then to access any button I could use

             Private Sub CmdBut_Click(Index As Integer)

                if index <= 100 then

                  My Code Here


             End Sub

    is that right ?
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Yes...the "Index" parameter tells you which button in your control array was clicked.

    Author Comment

    Thanks Very Much!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    Title # Comments Views Activity
    use like in If/Then vba 4 43
    VBA Modification 5 35
    VBA error replacing data 6 29
    bit defender blocks good applications 2 31
    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…
    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    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

    8 Experts available now in Live!

    Get 1:1 Help Now