+ Reply to Thread
Results 1 to 8 of 8

Enabling Reset Button

Hybrid View

  1. #1
    Registered User
    Join Date
    01-02-2017
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2013
    Posts
    6

    Enabling Reset Button

    Hello,

    I was wondering if someone could help me with the following. I have a reset button on my form, that I would like to become enabled when any of the fields on the form are not equal to their starting values, but not enabled when all fields are equal to their starting values. In this way seeing whether the reset button is enabled (greyed out) can serve as a visual tool for the user to see if he/she has made changes anywhere on the form.

    In principle, I can achieve this by writing a textbox_Change() sub for every textbox, drop down list, and option button, but it seems that this is not very efficient.
    Especially, given that the form itself contains 63 textboxes, 2 option buttons, and 4 drop down lists.

    I was wondering if someone could help me with this. Any help is greatly appreciated.

  2. #2
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Enabling Reset Button

    Unable to visualize without a sample workbook.Please upload a file with desensitized data.
    Teach me Excel VBA

  3. #3
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    867

    Re: Enabling Reset Button

    Quote Originally Posted by metabee View Post
    Hello,
    ...
    In principle, I can achieve this by writing a textbox_Change() sub for every textbox, drop down list, and option button, but it seems that this is not very efficient.
    ...
    .
    Actually this would be the most efficient way for the user (not for the coder indeed).

    You could also try try to loop through every control in userform using somenthing like
        For Each cControl In Me.Controls
    
            'take the control values into a label for exaple...
    
        Next cControl 
    
    ' based on the label caption activate/deactivate reset button
    but this code should be triggered by an event also... maybe a mandatory last field..
    .. and don't forget to have fun!
    Bogdan.

    mark SOLVED and Add Reputation if my answer pleases you

  4. #4
    Registered User
    Join Date
    01-02-2017
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2013
    Posts
    6

    Re: Enabling Reset Button

    I have attached a sample file with what I want to achieve.

    As soon as the value of any of the textboxes/combobox is not equal to its starting value, I want the reset button to be enabled.

    If all textboxes/comboboxes are equal to its starting value, i want the reset button to be disabled.

    This is working fine in the sample file.

    The problem is that for the original file, I have more than 70 fields, and it is not efficient to program it separately for every button.

    Hence why I was hoping someone has a smarter solution.

    Any help is greatly appreciated.
    Attached Files Attached Files

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Enabling Reset Button

    In general what I would do is put the Default values for each control in its .Tag property (at design time or start up)

    Then I would have a butReset tied to code like this.

    Private Sub butReset_Click()
        Dim oneControl as MSForms.Control
    
        For Each oneControl in Me.Controls
            Select Case TypeName(oneControl)
                Case "TextBox", "CheckBox", "ComboBox", "OptionButton"
                    oneControl.Value = oneControl.Tag
            End Select
        Next oneControl
    
        butReset.Enabled = False
    End Sub
    Then each control's change event would call this sub

    Sub ResetEnablement()
        Dim Enablement as Boolean
        Dim oneControl as MSForms.Control
    
        Enablement = True
    
        For Each oneControl in Me.Controls
            Select Case TypeName(oneControl)
                Case "TextBox", "CheckBox", "ComboBox", "OptionButton"
                    Enablement = Enablement And (oneControl.Tag <> CStr(oneControl.Value))
            End Select
        Next oneControl
    
        butReset.Enabled = Enablement
    End Sub
    Alternatly, you could just set the butReset.Enabled to True in every Change event without looking to see if the Change is "change back to default"
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Registered User
    Join Date
    01-02-2017
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2013
    Posts
    6

    Re: Enabling Reset Button

    Thank you very much for your answer, I am however still unable to get it to work ...

    I set me.Reset.Enabled=False for the initialisation, because if the form is first loaded, there is nothing to reset.

    However, when I type in any of the textboxes, it does not then become enabled...

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Enabling Reset Button

    I got the logic switched between ALL and ANY. Change this line


    Sub ResetEnablement()
        Dim Enablement as Boolean
        Dim oneControl as MSForms.Control
    
        Enablement = False
    
        For Each oneControl in Me.Controls
            Select Case TypeName(oneControl)
                Case "TextBox", "CheckBox", "ComboBox", "OptionButton"
                    Enablement = Enablement Or (oneControl.Tag <> CStr(oneControl.Value))
            End Select
        Next oneControl
    
        butReset.Enabled = Enablement
    End Sub

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,293

    Re: Enabling Reset Button

    Post Deleted.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

+ 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. Create running stopwatch/timer with 1 button (start/stop). No reset button.
    By leeroy2612 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-26-2021, 12:59 AM
  2. [SOLVED] I need to create a reset button that will reset rows containing a specific value
    By odin78 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 04-03-2016, 02:11 PM
  3. enabling a vba control form button in vba code
    By jeskit in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 02-27-2012, 06:56 PM
  4. Custom button enabling/disabling
    By FlyinJack in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-24-2009, 06:13 PM
  5. Protected Toolbars Button Enabling Possiblity.
    By gajendra.gupta in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-26-2007, 01:28 AM
  6. Enabling a button if full row is selected
    By bjwade62 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-01-2006, 06:06 PM
  7. Enabling more than one option button
    By Tempy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-22-2005, 10:06 AM

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