+ Reply to Thread
Results 1 to 3 of 3

A problem with adding and deleting dynamic controls in a userform

  1. #1
    Registered User
    Join Date
    11-12-2011
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    6

    A problem with adding and deleting dynamic controls in a userform

    Hello all, I have been tinkering about with a userform for the past week but I've come up against a slight problem.

    The Userform that I have created contains both dynamically created controls and a template.

    The template controls are all working fine and I have managed to get the userform to add dynamic controls with a button press (On the button press the userform adds 3 controls to the third page of the userform, 1 ComboBox, 2 TextBoxes and 3 Labels). On the next button press another set of controls are created just like the first set, but located below the previous set.

    For each "Add" button press this is continued, one set of controls at a time, down the page.

    My problem is this:

    I have been trying to work on coding a delete button that will remove/delete each set of controls each time the delete button is pressed.

    I'm sure some of you will ask why I don't just hide the controls instead but I would rather make this as tidy a job as possible and try to learn exactly why the code isn't working as it should be.

    I have had some reasonable success however I think the problem lies in my looping or recording/updating my integers properly.

    I have noticed when I press the "Add" button a number of times then press "delete" the button removes half the number of lines that I have added (that is to say if I press the "Add" button 4 times and then press "delete" the code removes 2 sets of lines instead of just one, if I press the "Add" button 10 times then press "delete" 5 lines are removed at once etc.)

    I have been unable to work out where I'm falling down on this, so any help on this or a push in the right direction would be appreciated.

    The code I have been tinkering with is below, apologies in advance for the lack of anotation or labels, I know it's bad form.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Thanks very much for looking through my code, hopefully a new set of eyes on here will point me in the right direction
    K

  2. #2
    Valued Forum Contributor
    Join Date
    10-13-2010
    Location
    Sunderland, England
    MS-Off Ver
    Excel 2007 (Home) / 2003 (Work)
    Posts
    740

    Re: A problem with adding and deleting dynamic controls in a userform

    Just from looking at the the Delete button code, it looks as if the iAddedCount = iAddedCount - 1 line is in the wrong place.

    I would expect it to come right at the end of the code, followed by an End If to match your If iAddedCount > 0 Then statement. But that's just from looking, I can't guarantee it'll work?

  3. #3
    Registered User
    Join Date
    11-12-2011
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: A problem with adding and deleting dynamic controls in a userform

    Hello brokenbiscuits, thanks very much for the input. I have this question up on another forum and got a resolution, thought I'd post the result here in case anyone was searching

    The problem was with the code for the delete button, the corrected code is:

    Please Login or Register  to view this content.
    Hopefully that will come in handy for someone in future
    K

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Userform & Dynamic Controls & Class Module
    By sarndt01 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 09-18-2014, 01:53 PM
  2. Adding more controls than will fit in visible area of userform
    By bberger1985 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-27-2013, 11:12 AM
  3. [SOLVED] Adding Controls to a userform Listview
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-29-2012, 07:36 AM
  4. (Closed)Dynamic Userform Controls With Event Handlers
    By stuart010 in forum Excel General
    Replies: 0
    Last Post: 04-30-2012, 11:32 AM
  5. Deleting Userform controls through code (Help)
    By stuart010 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-26-2011, 10:12 AM
  6. adding controls to userform at runtime
    By Ouka in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-18-2005, 03:11 PM
  7. [SOLVED] Adding controls to userform
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-25-2005, 08:06 AM

Tags for this Thread

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