+ Reply to Thread
Results 1 to 9 of 9

Intercepting multi page change

  1. #1
    Registered User
    Join Date
    01-17-2019
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    81

    Question Intercepting multi page change

    This may be a 'cant be done' buy thought I would ask the brain-trust ...

    I am trying to figure out a way to intercept when the user clicks on the tab of a form's multi-page so that I can test if there has been a change and, if there has, give the user the option to save BEFORE changing to the next tab. While I can intercept changes to the data, whatever I do I can't get the VbMsgBox to pop up before the page actually changes.

    I tried:

    Please Login or Register  to view this content.
    but it doesn't reset - presumably because by the time this runs, I am in effect, resetting the new multipage back to the new multipage.

    I am not entirely sure what the syntax is for holding a variable for the 'current' page and swapping back to it if the user wants to cancel but I'm pretty confident I can do that as a plan B.

    Effectively there are 3 options:

    1. User wants to save changes => run sub to save the data from tab or whole form
    2. User does not want to save changes => presumably I just don't run sub that transfers 'new' value to worksheet and reset any changed value on the multipage to value on worksheet
    3. User wants to cancel change => swap back to original multipage from new multipage

    My question really boils down to, can I ask the question (the VbMsgBox) and process the choice before the multipage changes from original to new? It looks like the act of clicking triggers the change multipage event before anything else gets to chime in. Is it possible to stop this or an easy way to bounce back to the original so, from the user perspective, nothing changed?

    Any thoughts on direction for me to try would be appreciated
    Attached Files Attached Files

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,003

    Re: Intercepting multi page change

    The simplest option is usually not to allow the user to directly change pages. Use your own buttons (or other controls) to control the navigation.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,052

    Re: Intercepting multi page change

    The problem is that page changes within the page change event don't work properly.

    Another option is to use a Sub to run the change event again on a timer. That, together with some global variables to remember the page etc, can make it work with the existing page tabs.
    I put something together in the attached file. I also changed it so that if it's cancelled the change flag isn't reset.
    Attached Files Attached Files
    Last edited by ByteMarks; 08-05-2024 at 03:16 PM.

  4. #4
    Registered User
    Join Date
    01-17-2019
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    81

    Re: Intercepting multi page change

    Thanks @ByteMarks, I was getting close to it but the tab refreshes just wouldn't work ... It feels like a bit of a poorly executed feature of Excel.

    I will see if I can extend your code to the main Workbook im trying to get to work.

    Very much appreciate the assist.

  5. #5
    Registered User
    Join Date
    01-17-2019
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    81

    Re: Intercepting multi page change

    @romperstomper Thanks for the note. I get where you are coming from ... I was trying to keep the interface simple, which was fine before I started incorporating logic to check for changes before swapping. I might rill with an alternate next time.

    Thanks

  6. #6
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,411

    Re: Intercepting multi page change

    One from my 'vault' of years ago - I have striped out all the unnecessary coding and left the demo of how I incorporated command buttons instead of page tabs - using this method you could intercept the command button action with a message box prior to the page change.
    Attached Files Attached Files
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  7. #7
    Registered User
    Join Date
    01-17-2019
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    81

    Re: Intercepting multi page change

    Thanks @torachan, that's an interesting approach ... I think I follow the logic, I guess the code for managing the 'change' would be easier to intercept within the button event itself and it would only show the tab when the event (including all queries/validation etc) was complete.

    I am getting past the multipage - I like Bytemarks solution but Multipage generally just seems a flawed feature within Excel and I get the feeling it will break in a new and unusual way later.

    I will see if i can do a proof of concept within my Workbook.

    Really appreciate the demo

  8. #8
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,411

    Re: Intercepting multi page change

    Basically you are correct - however you can direct the code flow to whatever you want n the command button/message box combination making the app very versatile.
    I have developed many apps over the years using the multipage and I would class it as one of the most useful controls - especially if you use it instead of multiple userforms keeping all the controls and variables in one envelope.
    Just to illustrate I have attached a couple of diverse apps - the questionnaire is self constructing (dynamic at run-time) - if add or delete blocks of ten in the question table the userform will alter accordingly without manual changes to code.
    The multiple listbox app acts in a similar manner - to keep track of Swiss rental property details - both apps just demonstrate the variety that can be accommodated - I am interested as to what way you consider the multipage to be flawed?
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    01-17-2019
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    81

    Re: Intercepting multi page change

    Thanks for the additional @torachan, I like the feature of the multipage generally but it seems a missed opportunity that you cant intercept the page change within the change page event. I also found it odd that when I forced a change back to the previous page, the tab changed but the page controls didn't. It just seems it could work in a more procedural fashion 'out of the box', expecting users to need more control over the tab changes (accepting your more advanced way of working around it).

    I will look at your additional examples and see if I can get my head around them

    Thanks

+ 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] Excel page in Multi-Page control has phantom controls
    By tfurnivall in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-19-2022, 09:47 AM
  2. Multi page order sheet with summary page
    By Dsmith22 in forum Excel General
    Replies: 9
    Last Post: 09-18-2017, 02:04 AM
  3. Multi worksheet change functions on one page.
    By ace_vfx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-16-2016, 09:14 AM
  4. Change location of commandbuttons on multi page in userform using vba
    By newbi004 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-19-2013, 10:13 AM
  5. [SOLVED] Excel VBA - Dynamically Adding a Page to a Multi-Page UserForm
    By eemiller1997 in forum Excel Programming / VBA / Macros
    Replies: 116
    Last Post: 12-13-2012, 05:26 PM
  6. [SOLVED] Combobox in page 2 of multi page userform excel 2003
    By AliiShariff in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-27-2012, 07:37 PM
  7. Replies: 3
    Last Post: 03-29-2006, 12:50 PM

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