Change Page on TAB Control

D

Dave G

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
 
S

storrboy

My thoughts are,

The BeforeUpdate event of the form allows you to cancel the current
process if some condition is not met. If the form is bound, then in
theory, all data on the form is related and must be updated at the
same time. Only worry about validation at this point because up until
then, it's still being edited.

In an Unbound form I think the user should either be free to tab
around OR control access to the tabs. One way is to hide the other
tabs when data is being edited and re-enabled when it is saved (or
needs to be validated). Or to control what tab they can move to and
when, provide Next and Previous buttons on the form to move between
the tabs, hiding and unhiding as they move around.
 
G

George Nicholson

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top