+ Reply to Thread
Results 1 to 3 of 3

Click events on buttons created at runtime only work on the last button created

  1. #1
    Registered User
    Join Date
    12-09-2008
    Location
    Hertfordshire, England
    Posts
    12

    Click events on buttons created at runtime only work on the last button created

    Hi,

    By following a similarly themed thread, I have created a class module and userform which a Collection of four CommandButtons to a form on initialisation. Now the idea is that the code will add a _Click event to each button, however, it only seems to work on the last button created. Can anyone tell me where I am going wrong?

    My class module code is:

    Please Login or Register  to view this content.
    And my UserForm code is:

    Please Login or Register  to view this content.
    Thanks
    Last edited by Treacle; 03-25-2010 at 05:45 AM.
    Core 2 Quad Q6600 o/c @ 2.9GHz, 4Gb DDR2 1066MHz, HD5770 1Gb 850MHz, 2 x 750Gb HDD (RAID 0), Benq G2222HDL 22" 1920 x 1080 LED, Win7 Ultimate

    Toshiba Satellite A665-11M, 16" 1366 x 768, i7 720QM 1.6GHz, 4Gb DDR2 1066MHz, GT330M 1Gb, 500Gb HDD, Win7 Home Premium

    Amiga 1200, 3.1 ROM, Blizzard 1230-IV 68030 50MHz CPU, 68882 FPU, 16Mb, 4Gb CF-based HDD, Custom IDE CDROM Drive, Indivision AGA Scandoubler, Custom VGA output, CWB 3.1 ADVSP, Benq G2222HDL 22" 1920 x 1080 LED (720p resolution)

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Click events on buttons created at runtime only work on the last button created

    You need to create the class instances within the loop too and add the object to the collection, not just its button:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    12-09-2008
    Location
    Hertfordshire, England
    Posts
    12

    Re: Click events on buttons created at runtime only work on the last button created

    Ah, sometimes then solution just stares you in the face and you don't see it! That worked a charm, thank you very much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1