Consulting

Results 1 to 7 of 7

Thread: MultiPage manipulation

  1. #1

    MultiPage manipulation

    I have a multipage object. My primary OK/Help buttons are outside the multipage. Currently I do error checking on the contents of each page when the user clicks OK, and return them to the page and object which has an error. I would also like to be able to do this when the user changes pages. For example, if the user finishes filling out "page 1" and then clicks on the tab for "page 2", I want to check the validity of "page 1" then and send them back to "page 1" if there is an error.

    One can detect page changes via MultiPage.Change(). Note that MultiPage.Value= also calls MultiPage.Change. Thus one cannot set MultiPage.Value inside MultiPage.Change(). Doing so causes the active tab to reflect the chosen .Value, but the page contents will not change.

    Anyone out there have a trick for doing this?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Here is one way.

    This shows how changing pages by selecting will trigger the MsgBox, and clicking a button that is on one of the pages will avoid it

    [vba]

    Option Explicit

    Private fDisable As Boolean

    Private Sub Commandbutton1_Click()
    fDisable = True
    Me.MultiPage1.Value = 1
    fDisable = False
    End Sub

    Private Sub MultiPage1_Change()
    If Not fDisable Then
    fDisable = True
    MsgBox "Selected page " & Me.MultiPage1.Value + 1
    fDisable = False
    End If
    End Sub

    Private Sub UserForm_Activate()
    fDisable = False
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Not quite. In my case, I have several inputs on a multipage, let us call them A, B, and C. If the user inputs something in C, then they must also enter something in B. I cannot check the validity of the inputs until the user (a) clicks ok outside the multipage or (b) when they move to the next page.

    The code for checking when they click OK is straightforward and works fine, but I'd rather catch errors on the page they are made. The problem is getting the code to redirect them back to the page they made the error on. The logical place to do this is inside multipage.Change(), but as noted in my first post, one cannot simply change the multipage.Value in multipage.Change().

    What the code xld provided does is pop up a dialog box when clicking on the tabs to navigate, but ultimately you still go to the page the user selected. What is needed is to go back to the page the user came from when they select another page.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by falconwing
    The code for checking when they click OK is straightforward and works fine, but I'd rather catch errors on the page they are made. The problem is getting the code to redirect them back to the page they made the error on. The logical place to do this is inside multipage.Change(), but as noted in my first post, one cannot simply change the multipage.Value in multipage.Change().
    I don't see why not

    [vba]

    Private fDisable As Boolean

    Private Sub MultiPage1_Change()
    If Not fDisable Then
    fDisable = True
    If Me.MultiPage1.Value = 2 Then Me.MultiPage1.Value = 1
    fDisable = False
    End If
    End Sub
    [/vba]

    What I gave you was an example to work with, not a full blown solution to a problem I haven't seen.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    I've attached a document which will show the multipage behavior. On my XL2003, XPSP2, when I force an error and click on the tab, the active tab is correct, but the active page is not.

    Thanks.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim prevTab As Integer
    Private fDisable As Boolean

    Private Sub btn1_2_Click()
    Me.MultiPage1.Value = 1
    End Sub
    Private Sub btn1_3_Click()
    Me.MultiPage1.Value = 2
    End Sub
    Private Sub btn2_1_Click()
    Me.MultiPage1.Value = 0
    End Sub
    Private Sub btn2_3_Click()
    Me.MultiPage1.Value = 2
    End Sub
    Private Sub btn3_1_Click()
    Me.MultiPage1.Value = 0
    End Sub
    Private Sub btn3_2_Click()
    Me.MultiPage1.Value = 1
    End Sub

    Private Sub chk1_Click()
    fDisable = Not chk1.Value
    End Sub

    Private Sub MultiPage1_Change()
    Dim strg1 As String
    Dim strg2 As String

    strg1 = "Previous Tab = " + Str(prevTab) + " (page " + Str(prevTab + 1) + ")"

    If Not fDisable Then
    fDisable = True
    Me.MultiPage1.Value = prevTab
    fDisable = Not chk1.Value
    End If
    prevTab = MultiPage1.Value
    strg2 = "Active Tab = " + Str(MultiPage1.Value) + " (page " + Str(MultiPage1.Value + 1) + ")"
    Lbl4.Caption = strg1 + vbCr + strg2
    End Sub

    Private Sub UserForm_Activate()
    fDisable = True
    End Sub

    Private Sub UserForm_Initialize()
    prevTab = 0
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Even with this revised version of the code, in my environment the tab shows the tab I want to send the user back to, but the contents of the page still shows the page of the tab they clicked on. Thanks for trying anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •