+ Reply to Thread
Results 1 to 13 of 13

Muultiple userform 'reset' code question

  1. #1
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161

    Muultiple userform 'reset' code question

    I have 30 commandbuttons on a page that open 30 different userforms.

    On each userform there is a 'reset' command button that resets form data.

    I have a 'master reset' commandbutton that resets data in all forms.

    Currently I am using the code below to accomplish this. There has to be a better way. Any ideas would be appreciated.

    If CommandButton1.BackColor = &HFFC0C0 Then
    Load UserForm1
    UserForm1.Reset_Click
    Unload UserForm1
    End If
    If CommandButton2.BackColor = &HFFC0C0 Then
    Load UserForm2
    UserForm2.Reset_Click
    Unload UserForm2
    End If

    etc. etc.

    Cheers

    PeterT

  2. #2
    Forum Contributor
    Join Date
    12-12-2005
    Posts
    667
    The only potential flaw I saw is to replace Unload UserForm1
    with UserForm1.Hide
    Best regards,

    Ray

  3. #3
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161
    Thanks Ray,

    If I hide the forms, as there are 30 of them, wouldn't that chew up a lot of memory resources?

    Another question, is it necessary to 'load' the form to perform an action on it?

    Cheers

    Peter

  4. #4
    Registered User
    Join Date
    10-12-2006
    Posts
    18
    I'm pretty new to excel, so you may want to take this with a pinch of salt, but would it be possible to do something like this:

    Please Login or Register  to view this content.
    I doubt it'll be much faster, but the code is nicer and it allows more flexibility if the code needs to be changed in the future.

    Like I say though, I'm pretty new to excel - I don't know if this will actually work.

  5. #5
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161
    Thanks Aelyn

    Just tried the code is stops with a compile error on the "If CommandButtons" line

    error says "fuction or Sub" not defined.

    I'll play around with it a little more!

    Cheers

    Peter

  6. #6
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161
    Still stuck with this, any ideas very welcome!

    Cheers

    Peter

  7. #7
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by peter.thompson
    Still stuck with this, any ideas very welcome!

    Cheers

    Peter
    Testing, for the loop, do you have buttons 1 to 30? - or have you deleted one within the range

    Perhaps a 'is nothing' test is needed.

    ---
    Si fractum non sit, noli id reficere.

  8. #8
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161
    Thanks Bryan

    CommandButtons 1 to 30 are definitely there - the inefficient code that I'm using now (Using an 'If CommandButton1' etc. repeated 30 times works fine).

    Go figure!

    Stumped!

    Cheers

    PeterT

  9. #9
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161
    Still stumped on this one - any ideas appreciated.

    Cheers

    Peter

  10. #10
    Forum Contributor
    Join Date
    12-12-2005
    Posts
    667
    Your additional question:
    Is it necessary to 'load' the form to perform an action on it?
    Yes.
    You repeat similar code 30 times, so you think this is inefficient. It isn't. If it ain't broken don't fix it!

  11. #11
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161
    Thanks for your reply Ray.

    Would still like to use less lines of code though!

    Cheers


    Peter T

  12. #12
    Forum Contributor
    Join Date
    12-12-2005
    Posts
    667
    Why?
    Using loops, select, choose.... are not particularly efficient!
    Often the longest codes are the most efficient! I've experienced it often!

  13. #13
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161
    Ray, thanks for the info - I didn't know that!

    Cheers

    PeterT

+ 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