PDA

View Full Version : MultiPage manipulation



falconwing
09-11-2007, 02:19 PM
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?

Bob Phillips
09-11-2007, 03:32 PM
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



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

falconwing
09-12-2007, 05:39 AM
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. :)

Bob Phillips
09-12-2007, 05:47 AM
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



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


What I gave you was an example to work with, not a full blown solution to a problem I haven't seen.

falconwing
09-12-2007, 07:33 AM
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.

Bob Phillips
09-12-2007, 07:53 AM
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

falconwing
09-12-2007, 08:06 AM
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.