Google Answers Logo
View Question
 
Q: Automatic move to next Access tab page ( Answered 4 out of 5 stars,   0 Comments )
Question  
Subject: Automatic move to next Access tab page
Category: Computers > Software
Asked by: bruces-ga
List Price: $15.00
Posted: 06 Oct 2002 10:41 PDT
Expires: 05 Nov 2002 09:41 PST
Question ID: 73253
I’m using Access 2002. My database is in Access 2000 format.

I’m designing a form to collect responses to a 40-item questionnaire.
I can fit four list boxes on a screen, so I plan to have 11 tab pages
(one page at the end for collecting identifying information) on my
form. To ease the task for the user, I’d like to have an automatic
movement to the next page. For instance, when the user clicks on the
choice for Question 4 (the last of the items on Page1), the focus
automatically shifts to Question 5 (the first of the items on Page2).

I know about entering code as an event procedure. I assume that I need
to enter code on the Event tab for the List Box that contains the
Question 4 answer.

1.	For which Event do I enter the code (After Update, On Enter, On
Click)?

2.	What code should I enter?

3.	Can I use this same method for all of the moves from one page to
the next? (I know how to set a command to close the form. My plan is
to have a command button on the last page that says, “You may review
your answers by clicking on the tabs. When you are done, click on the
button to close the form.”)

Thanks.
Answer  
Subject: Re: Automatic move to next Access tab page
Answered By: twitch-ga on 06 Oct 2002 12:56 PDT
Rated:4 out of 5 stars
 
bruces-

Thanks for the question. First, I feel that I should caution you that
automatically switching pages when a user selects a value may cause
aggrivation for the user- it will happen so fast that the user will
not always be certain that he or she clicked the appropriate value.
You may want to run the changes by your users to get their feedback.

That being said, there are a couple of ways that you can approach
this- but you probably want to use the Click event to handle your code
in both approaches.

The first option is to have a separate Click event handler for the
last list box on each page that will explicityly set the focus to the
first list box on the next page. The other option, which I favor and
for which the following code applies, is to have a generic Click event
handler that automatically sets the focus to the next page. This
approach, however, requires that you set the TabOrder for each page so
that the appropriate ListBox always has the focus when the Page of the
Tab control switches. The following sample code can be used to
accomplish your goal:

[---------begin code listing-------------]
' a generic subroutine that will handle the click events in the 
' proper fashion. we call this routine from every List Box that needs
to
' change the page
Private Sub HandleClick()

    Dim thisPage As Control
    
    Set thisPage = Me.ActiveControl.Parent
    If thisPage.PageIndex = (tabMyTab.Pages.Count - 1) Then
        MsgBox ("You have completed the form")
        Exit Sub
    End If
    
    tabMyTab.Pages(thisPage.PageIndex + 1).SetFocus

End Sub
[---------end code listing-------------]


With that one routine you can handle the click event in any ListBox
you like. Simply add the following line of code to any ListBox Click
Event handler that needs to be able to switch the page:

Call HandleClick

So if you had a ListBox named List16 its Click event handler would
look like this:

[---------begin code listing-------------]
Private Sub List16_Click()
    Call HandleClick
End Sub
[---------end code listing-------------]


Hopefully this solves your problem for you. Please let me know if
there is anything that I might help clarify.


Search strategy
---------------
None, I used my experience with Access and Visual Basic to find a
solution.

Request for Answer Clarification by bruces-ga on 06 Oct 2002 15:19 PDT
Twitch,
Thank you for the prompt reply, the detailed instructions, and your
wise counsel that what I intend to help the users might in fact
irritate them. I will get feedback from them, as you suggested.
When I run the code, I get an error message: “Compile error: Variable
not defined”
The offending variable seems to be “tabMyTab” in “If
thisPage.PageIndex = (tabMyTab.Pages.Count - 1) Then”

Clarification of Answer by twitch-ga on 06 Oct 2002 21:32 PDT
>When I run the code, I get an error message: “Compile error: Variable
> not defined”
> The offending variable seems to be “tabMyTab” in
> “If thisPage.PageIndex = (tabMyTab.Pages.Count - 1) Then

Grrrrr...I'm terribly sorry about that. 'tabMyTab' is what I named
my TabControl in the Form. Just replace that with whatever you named
your Tab Control (e.g. Tab1) and everything should be fine. Sorry
about the mistake- I should have caught that before I posted the
answer.

Please let me know if you run into any other problems.
bruces-ga rated this answer:4 out of 5 stars
Wonderful answer, but the error in the first response was a bit of a nuisance.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy