George, thanks very much. I am very much an amateur but I follow your code
-- but don't get it completely.
See my code below as used. My form opens with tab0 visible and clicking any
other tab returns "unexpected value". then I get "phone" and "pages same",
but tab0 (phone data) is not the focus.
Don't know about the "unexpected value" but I'm thinking the two messages
are because the revisit. How does this refocus to tab0?
Code:
Private Sub tabNewClient_Change()
Static mlngTabpage As Long
' Note: Me.tabNewClient = the "new" page the user wants to move to
' mlngTabpage = the stored value of the "old" page we want to leave
If Me.tabNewClient = mlngTabpage Then
' No page change. Assume a forced (recursive) visit to the Change event: Exit
MsgBox "pages same"
Exit Sub
End If
Select Case mlngTabpage
' Check old/prior page (mlngTabpage) before allowing movement to new Page
(Me.tabNewClient)
Case 1
If IsNull(Me.txtPhone1.Value) Or Me.txtPhone1 = 0 Then
MsgBox "phone"
' Validation failed. Force user back to "previous" page & Exit
' Note: this 'change' will cause the Change event to fire a 2nd time
Me.tabNewClient = mlngTabpage
' (This is of course the same as: Me.tabNewClient = 1)
Exit Sub
End If
Case 2
If IsNull(Me![Petsfrm].Form!txtName1.Value) Then
MsgBox "name"
' Validation failed. Force user back to "previous" page & Exit
' Note: this 'change' will cause the Change event to fire a 2nd time
Me.tabNewClient = mlngTabpage
' (This is of course the same as: Me.tabNewClient = 2)
Exit Sub
End If
Case Else
MsgBox "Unexpected value"
End Select
' If we got this far then Page change is being allowed. Store its value
mlngTabpage = Me.tabNewClient
End Sub
--
Thanks for your help,
Chris
George Nicholson said:
The skeleton of an approach:
' (Form Module level or app level declaration)
Private mlngTabpage as Long
'-----------
Private Sub tbcTabControl_Change()
' Note: Me.tbcTabControl = the "new" page the user wants to move to
' mlngTabpage = the stored value of the "old" page we want to
leave
If Me.tbcTabControl = mlngTabpage Then
' No page change. Assume a forced (recursive) visit to the Change
event: Exit
Exit Sub
End If
Select Case mlngTabpage
' Check old/prior page (mlngTabpage) before allowing movement to new
page (Me.tbcTabControl)
Case 1
If somePageOneValidationTest = False Then
' Validation failed. Force user back to "previous" page &
Exit
' Note: this 'change' will cause the Change event to fire a
2nd time
Me.tbcTabControl = mlngTabpage
' (This is of course the same as: Me.tbcTabControl = 1)
Exit Sub
End If
Case 2
'........
Case Else
MsgBox "Unexpected value"
End Select
' If we got this far then Page change is being allowed. Store its value
mlngTabpage = Me.tbcTabControl
End Sub
HTH,