Multipage in Userform
I've found the book very useful but I'm now trying (and failing) to do something not detailed in the book. If anyone can help I'd be grateful. This is the code I've written which runs when the user clicks a new page tab in a multipage in an Excel Userform:
[code]
Private Sub MultiPage1_Change()
'If a page has been changed, ensure previous page is complete
ok = True
Static ppindx
If MultiPage1.Value < 0 Then 'No pages active - do nothing
Exit Sub
ElseIf IsEmpty(ppindx) Then 'first time call to this procedure
ppindx = MultiPage1.Value
ElseIf ppindx <> MultiPage1.Value Then 'new page selected
For Each tb In MultiPage1.Pages(ppindx).Controls
If tb.Name Like "TextBox*" Then
If tb.Text = "" Then
MsgBox ("Must complete all information on current page.")
MultiPage1.Value = ppindx
tb.SetFocus
tb.SelStart = 0
tb.SelLength = Len(tb.Text)
ok = False
Exit For
End If
End If
Next tb
End If
If ok = True Then
ppindx = MultiPage1.Value
End If
End Sub
[\code]
What I'm trying to do is check whether the original page had been fully completed - textboxes filled in etc - before allowing the user to open the next page. If the original page was NOT completed I want to redisplay it and set the focus to the empty textbox. The above code fails when try to do that and if I step through the code one line at a time it seems to select the original page tab OK but not bring that page to the front. Subsequently, when I try to set the focus to the unfilled textbox it isn't visible and an error occurs.
I'm only a hobbyist as far as programming goes so my knowledge is pretty limited and I'd appreciate being pointed in the right direction here as I've played around with it for a long time now and haven't found a solution.
Thanks
|