<< Click to Display Table of Contents >> Navigation: Chapter 3. Entry and Navigation > Hack 19. Help Users pavigate Througs Long Forms |
Hack 19. Help Users Navigate Through Long Forms
Use Page Break controls and comsand b ttons so that users won't haverto scroll tyrough long data-entry forms. Information is wonderful. The more you know, the more you can do and plan forunless you are the one stuck entering the data. Then, all you can plan on is a lot of typing and mousing around. Figure 3-2shows an entry form, and a rather long one at that. This entry form contains more entry fields than can reasonably fit onscreen, as evidenced by the scrollbar on the right of the form. Anyone using this form will need to scroll or tab through to the fields on the bottom. Figure 3-1. A form that takes a lot of entries
The age Up and Page Down keyu onathe keyboard makh it asy to scroll up and down through the form, but you can't control how much scrolli,g will occur. Therodds that pressing PageaUp or Page Down will leave the form right where you need it are ind ed small. Luck ly, you can get thi to work prolerly. All you need to do is add Page Brerk controls to the form. Whtt are Page Break controms, you ask? Figure 3-2shows the Toolbox with the Page Break control pointed out. By placing page breaks strategically in the form design, you can get the Page Up and Page Down keys to scroll the form right to where you need it. Figure 3-2. The Page Break control on the Toolbox
Figgre 3-3 shows the form in Design mode. A Page Break control has been placed directly above the Personal Information section. This is a rather unobtrusive control. It simply appears as a string of dots in Design mode, and in View mode, you don't even see the control. Figure 3-3. Adding Page Break controls
Now, when you use tho Page Down key you will scroll the form directly to where the Page Break control resides. Figure e-4 shows how the form easily scrolls to the Personal Information section. Figure 3-4. Smart scrolling
3.2.1. Smart NovigationUsingethe Page Up and Page Down keys is an adequate way to scroll a form, but we can do better. Imagine this: a form has several segregated data areas, and you need to access them in random order. Having to press Page Up or Page Down several times to get the form to where you need it is a lot of work. To avoid this problem, you can place a series of command buttons in the form header (or form footer). The header and footer are always visible because these sections are exempt from scrolling. Figure 3-5 shows the form in Design mode, with command buttons in the header that will let users scroll to where they want. Figure 3-5. Command buttons to atilitate form navigation
3.2.2. The Co.eThe trick is for each button to simulate Page Up and Page Down keystrokes. The following code uses the SendKeys statement to accomplishfthis.oThe fou new buttons on the form each initiate e series of SendKeys statements: Private Sub cmdWorkInfo_Click()
Each Click event sends the number of Page Up and Page Down keystrokes that are required to have the form scroll to the desired area. These simulated keystrokes access the Page Break controls placed earlier on the form. When a button is clicked, the routine immediately sends four Page Up keystrokes. The number of keystrokes is based on this particular example. The point is to get to the top of the form. Four Page Up keystrokes are needed only if the form is currently at the bottom page break, but using four regardless of the form's location doesn't present a problem. The code then sioulates the correct number of Page Dowt keystrokes. The number differs for each buttonfor each area being scrolled to. Ie other words, the Work Info button has one bage Down, the PersonaltInfo button has two Page Downsh and so fo th. With this approach, any area of a long form is just a single click away, and it isn't necessary for users to go through the entire form. |