Using Multi Page and Tab Strip Controls

The central object of the custom form shown in Figure 10-16 is a MultiPage control that consists of two pages. The first page contains text and combo boxes to gather student data, such as Social Security number (SSN), first and last name, year of study, and major. A group of option buttons at the top of the form allows you to specify the student's status: New or Active. If the student's data has not yet been entered in a worksheet, the student's status is New. When the form is first loaded, the New option button is automatically selected. When you want to review or update data for existing students, clicking the Active option button will display the RefEdit control used to populate the list box control with students' names, as entered on the worksheet.

1. Insert a new UserForm into the current project and rename it Students.

2. Change the form's Caption property to Students and Exams.

3. Click the MultiPage control in the Toolbox, and then click in the upper left-hand corner of the form and drag the mouse down and to the right to draw a large frame.

4. Right-click the Pagel tab, and choose Rename from the shortcut menu. Type Students in the Caption text box, and enter S in the Accelerator Key field. In the same way, rename the second page Exams, and enter x in the Accelerator Key field.

5. Click the Students tab. Using the controls in the Toolbox, add to the Students page all of the controls shown in Figure 10-16. Follow these guidelines:

■ The Status frame contains two option buttons. Set the Caption property of these buttons to New and Active. Next, change the Name property of the first button to optNew and the second one to optActive.

■ Text boxes are titled using label controls with their Caption property set to SSN, Last Name, and First Name. Change the Name property of the text box controls to txtSSN, txtLast, and txtFirst.

■ Combo boxes are titled using label controls with their Caption property set to Year and Major. Set the Name property of the combo box controls to cboxYear and cboxMajor. To allow the user to select only one of the specified items, set the following properties for each of the combo boxes: MatchRequired to True, MatchEntry to 1-fmMatchEntryComplete.

■ Place the Name Range label above the RefEdit control. Set the Name property of the RefEdit control to refNames.

■ Set the Name property of the list box control to lboxStudents. Set the ColumnCount property to 2 to display two columns of data.

■ Set the Caption property of the command buttons to OK and Cancel, and set their Name property to cmdOK and cmdCancel.

Image Control Excel Vba

Figure 10-16:

The MultiPage control can contain two or more pages. Each page shows a different set of controls.

Figure 10-16:

The MultiPage control can contain two or more pages. Each page shows a different set of controls.

The second page of the MultiPage control (Figure 10-17) is used to record and display information related to exams taken. This page contains two objects. The label control has a temporary title "Last, First." At run time, this label will display the student's name as selected on the previous page.

The second object on this page is the TabStrip control. It contains four tabs with the names of the exam subjects. Although this example displays the tabs at the top of the form, Visual Basic also allows you to set the orientation of the tabs to bottom, left, or right. As you navigate from tab to tab, you can see the same controls. Only the data displayed inside each control changes.

1. Click the Exams tab in the MultiPage control.

2. Click the Label control in the Toolbox and click in the upper left-hand corner of the Exams page. Drag a rectangle large enough to hold a person's first and last name.

3. In the Properties window, set this label's Name property to lblWho. Set the label's Caption property to Last, First. Set the Font property to Arial, Bold, 14 point.

4. Click the TabStrip control in the Toolbox. Click on the form just below the label control, and drag the mouse until the strip is the size and shape you want (see Figure 10-17). By default, the TabStrip control will display two tabs: Tab1 and Tab2. To add new tab pages, first click inside the TabStrip control to select the TabStrip object. Click again until the hatched frame around the TabStrip object appears in bold. Right-click any tab, and choose New Page from the shortcut menu. Visual Basic will add Tab3. Use the same method to add Tab4. Right-click each of the tabs, and choose Rename from the shortcut menu. See Figure 10-17 for the names of all the tabs. Notice that each tab name has an underlined letter, which allows the user to access the tab from the keyboard. For example, pressing Alt+E will activate the English tab.

5. Click the English tab and begin drawing the following controls:

■ If the Toolbox contains only one page titled Controls, go back to the earlier section in this chapter titled "Tools for Creating User Forms" to find out how to add a Calendar control to the Toolbox. Then place the Calendar control inside the TabStrip control, as shown in Figure 10-17. Set the ShowDateSelectors property for the Calendar control to True.

■ Add the Enter/Change Grade label and a combo box control. Set the Name property for the combo box to cboxGrade.

■ Add two labels with the Caption property set to Grade and Date and the Name property set to lblGrade and lblDate. Change the SpecialEffect property for both labels to 3-fmSpecialEffect-Etched.

Tabstrip Vba

Figure 10-17:

The outside frame contains the MultiPage control. The inside frame contains the TabStrip control.

Figure 10-17:

The outside frame contains the MultiPage control. The inside frame contains the TabStrip control.

Tip 10-6: Setting the TabStrip Control

The best way to set up a TabStrip control is to add it as the first control to the form and then place other controls inside it. However, if you already have controls placed on the form, you can draw the TabStrip control over these controls and use the Send to Back command to send the TabStrip to the bottom of the Z-order.

The Students and Exams custom form allows you to enter new data or display data as entered in the worksheet. Figure 10-18 shows the worksheet used by this form.

1. Prepare the worksheet displayed in Figure 10-18.

2. Add the Display Form button to your worksheet and assign to it the DoStudents procedure.

3. In the Visual Basic Editor screen, add a new module to the current project, and set the module's Name property to InfoStudents.

4. Enter the following DoStudents procedure in the InfoStudents module:

Sub DoStudents()

Students.Show End Sub

Sub DoStudents()

Students.Show End Sub

□fc ChdpTO.xl

-1 □ 1

A 1

B

c & 1

E

F 0

M 1 1

J 1 K

L i

_w_

-

1

Display Form

English

French

Math

Plrysics

2

SSN

Last Name

Fii st Hame Year

Major

Grade Date

Grade

Date

Grade Date

Grade

Dite

4

5

S

-

7

8

9

10

i1

1 ► n|\ Info Survey \sheet2 / sheet3

/

1

Figure 10-18: Supporting spreadsheet for Students and Exams sample application

Figure 10-18: Supporting spreadsheet for Students and Exams sample application

5. Return to the worksheet, and click the Display Form button to test the DoStudents procedure.

6. Close the form by clicking the Close button in the upper right-hand corner of the form.

+6 0

Responses

  • harrison
    How to rename tabs in VBA tab strip?
    6 years ago
  • Zewdi
    How to populate a vombo box on page 2 of multipage?
    6 years ago
  • camelia
    How to place text field inside the tabstrip control?
    6 years ago
  • Belladonna
    How to use textbox in multipage control in vba?
    6 years ago
  • ethel
    How to rename multpage tab labels VBA?
    6 years ago

Post a comment