+ Reply to Thread
Results 1 to 8 of 8

Method to trap Userform changes

  1. #1
    Registered User
    Join Date
    08-01-2010
    Location
    Swindon, Wiltshire
    MS-Off Ver
    Excel 2003
    Posts
    30

    Cool Method to trap Userform changes

    I have a dynamic multipage userform with textboxes and optionbuttons. I am trying to include a routine that will allow me to ask the user if they want to save any changes made on any of the pages or any of the optionbuttons. It would be too complex to test each control to see if it has changed and I was wondering if there is a global test to trap data changes on a user form.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Method to trap Userform changes

    Hi,

    I'm not aware of any such global parameter, but if you were to store the results of all the relevant objects in an Excel table, you could then use a 'before' table (which would be a copy of the table before you initialise your form), and in Excel have a cell (or cells) which compare the before/after tables and return say a 1 or 0 value. Then just use the value of this test cell(s) to decide whether to save changes or not.

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Method to trap Userform changes

    Hello BillWilts,

    You mention this a dynamic UserForm. Does that mean you are creating this UserForm at runtime?

    Richard is correct that there is no global event that is raised whenever a control's value has changed on the UserForm. I find it curious you only want to know that something has changed without first knowing if it is valid before you save it.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

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

    Re: Method to trap Userform changes

    If you are looking to have a UnDo changes button, you could put the previous values in each control's .Tag property.

    If you want to record all the changes, a generic routing become more problematic. In addition to storing the values of the controls, the .Tag property might also be a factor since many UFs use Tag properties for their operation. Similarly, ListBoxes and ComboBoxes have two problems, accomidation of multi-select and changing List contents is an issue. Some UF's change the ColumnWidths in the course of their operation. Also the .Visible and .Enable properties often change in response to a users actions.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Method to trap Userform changes

    You can easily store the userform's VBA code when initializing and compare that to the userform's VBA code at any given point later. (or compare the exported frm files at different points).
    But why would you do it ?



  6. #6
    Registered User
    Join Date
    08-01-2010
    Location
    Swindon, Wiltshire
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Method to trap Userform changes

    Thanks to all for the replies.

    The form is created at run time based on the cells from two worksheets. The purpose of the application is to create a contract as a Word document containing blocks of text using parameters (e.g customer name, country, etc.) and optional clauses selected via check boxes and option buttons.

    The idea trapping of changes is that a contract might be written out for Customer A and then the identical contract for Customer B. As the only change is the customer name, it is probably not worth saving the changes but it would be nice to ask the user the question!

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Method to trap Userform changes

    Please explore Word's builtin mailmerge-facilities.

  8. #8
    Registered User
    Join Date
    08-01-2010
    Location
    Swindon, Wiltshire
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Method to trap Userform changes

    I don't have a problem with the Word part. I can write out a fully formatted document with headers, footers and a table of contents.

    The question was about a simple way of trapping any changes made on an Excel user form without having to test each individual control.

    On the basis this is a nice to have (users will just need to save all of their edits!) and that a simple answer probably does not exist, I think I need to let this one go...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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