One approach would be to create a form level variable to contain a reference
to the LastUsedPage (index number or page name).
In the tab control's OnChange event:
- if validation passes, update LastUsedPage variable to new value
- if validation fails, go back to page specified by the (unchanged)
LastUsedPage value.
Note that this doesn't really prevent them from changing pages, but it will
put them back where they "came from" if validation fails.
Notes:
-You would have to provide an initial value for CurrentPage on FormLoad
or something similar.
-Moving back to LastPageUsed on validation failure will (i believe)
cause OnChange to fire a 2nd time. To prevent validation from occuring a 2nd
time, you'd need to structure your code similar to the following air code:
Dim bolValid as boolean
If LastUsedPage <> CurrentPage# then
bolValid = False
'User is trying to change pages. Validate the LastUsedPage
Select Case LastUsedPage
Case 0
'Validate page 0
If x = x then bolValid = true
Case 1
......
End Select
If bolValid = false
' Validation failed. return user to LastUsedPage
Me.MyTabControl = LastUsedPage
End If
End If
HTH,
"Dave G" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In Access 2003 I have a form with a TAB control on it with 10 pages.
> As a user leaves one page for another I would like to trigger a little
> data validation on that page. This almost works using the On Change
> event to run a little function. BUT, if the validation fails I want to
> stop them going to the newly selected page and keep them on the page
> with the problem, but it seems I can't stop them going to the newly
> selected page.
>
> Is there a way to either
>
> - prevent them leaving a page, or
>
> - returning to previous page
>
> Thanks
> Dave
>
|