Announcement

Collapse
No announcement yet.

VBA Multipage Control Displays wrong page

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBA Multipage Control Displays wrong page

    Hello,

    I have a multipage control on a userform where when data is changed on the form, the user must save the changes or cancel the changes prior to switching to the other page on the multipage control. I have the following code:

    Code:
    Private Sub MultiPage1_Change()
        If mDataChanged And MultiPage1.Value = 1 Then
            ' If data has changed and user is attempting to switch to print page without saving updates
            MsgBox "             Your current changes have not been saved." & vbCrLf & _
                   "Please Save or Cancel your changes before selecting the print page"
            MultiPage1.Value = 0 ' Remain on current page, do not switch
        End If
    End Sub
    The strange thing is that when the user has not saved/cancelled changes and attempts to change pages, the appropritate message shows up, the correct tab is selected at the top of the form, but the page displayed is the page the user attempted to switch to. Is there another way to show the correct page in order to be certain the correct page is displayed, not just the tab at the top of the control?

    Any suggestions?
    Thanks,
    Dave

  • #2
    Re: VBA Multipage Control Displays wrong page

    The code as written works for me (assuming that mDataChanged is a boolean value that acts appropriatly).
    Have you tried adding
    Code:
    Me.Repaint
    at the end.

    If that doesn't work, what is mDataChanged?

    Alternatly, you could change things so that rather than set mDataChanged to True/False, you could set MultiPage1.Pages(1).Enabled to False/True.

    Comment


    • #3
      Re: VBA Multipage Control Displays wrong page

      I've seen that behaviour a lot with multipages. Best solution I can suggest is to not allow the user to use the tabs to change pages. Hide the tabs and replace them with your own buttons that only change page after validating the current data.
      Rory
      Theory is when you know something, but it doesnít work. Practice is when something works, but you donít know why. Programmers combine theory and practice: nothing works and they donít know why

      Comment


      • #4
        Re: VBA Multipage Control Displays wrong page

        Originally posted by mikerickson View Post
        The code as written works for me (assuming that mDataChanged is a boolean value that acts appropriatly).
        Have you tried adding
        Code:
        Me.Repaint
        at the end.

        If that doesn't work, what is mDataChanged?

        Alternatly, you could change things so that rather than set mDataChanged to True/False, you could set MultiPage1.Pages(1).Enabled to False/True.

        I tried "me.repaint" this does not work. Thanks for the view and attempt to fix.

        Comment


        • #5
          Re: VBA Multipage Control Displays wrong page

          Originally posted by rory View Post
          I've seen that behaviour a lot with multipages. Best solution I can suggest is to not allow the user to use the tabs to change pages. Hide the tabs and replace them with your own buttons that only change page after validating the current data.
          This seems to be the way to go. Then the tab only changes when I command it to, not the page. For whatever reason, it only switched the tab heading when using the "Multipage1_Change" event to validate.

          Thanks for the tip.
          Dave

          Comment

          Working...
          X