![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
Adding Buttons To The ToolbarThat was a long detour to cover the details of the Toolbar control. Getting back on track, its time to create the three buttons for the Toolbar on your MDI form. Using the techniques explained earlier, add three buttonsleaving all of their properties at the default setting, except as shown in Table 22.3. After adding these buttons, close the Toolbars property sheet. Your MDI form should resemble Figure 22.6.
As you might guess, responding to Toolbar button clicks is accomplished in an event procedure. The Toolbar object has a ButtonClick event procedure that is called when any of the controls buttons are clicked on. This procedure is passed a type Button argument that specifies which button was clicked on. You can query the Button arguments properties to identify the button, and you can use any of the properties that are unique to each button, such as Index or Caption. To add code to this event procedure, right-click on the Toolbar and select View Code from the pop-up menu. A Code Editing window opens; if necessary, select ButtonClick from the Procedure list at the top of the window. The code for this procedure is shown in Listing 22.1. Notice that you respond to clicks of the Customers and Wines buttons by displaying the appropriate form. These forms havent been designed yet, but you can reference them in code, as long as you dont try to execute the code (which would cause an error message, of course). Clicking on the Exit button displays a message box first, confirming that the user wants to exit, and then uses End to terminate the program. Listing 22.1 The Toolbar controls ButtonClick event procedure. Private Sub Toolbar1_ButtonClick(ByVal Button As Button) Dim Reply As Integer Select Case Button.Caption Case Customers frmCustomers.Show Case Wines frmWines.Show Case Exit Reply = MsgBox(Quit program - are you sure?, _ vbYesNo + vbQuestion, Quit?) If Reply = vbYes Then End End Select End Sub One last thing before you leave the MDI form: place the following line of code in the General section of the forms code: Public EnteringRecord As Boolean Then, put this line in the Form_Load event procedure: EnteringRecord = False These lines declare the flag variable and initialize it to the proper value when the program loads. Designing The Customers FormThe next task is to design the form to display customer information. To add a new form to the project, select Form from the Insert menu. This form will have the Name property frmCustomers and will be saved with the file name CUSTOMERS.FRM. You need to add the following items to this form:
When you place the Text Box controls on the form, add them in the order that a user would want to move between themthat is, in the same order as the fields are arranged in the database table. By adding the controls in this order, the tab order will be arranged similarly, and the user can Tab and Shift+Tab between Text Boxes in the most efficient order. Although you can change tab order later, after adding the controls, adding them in the correct order now saves time. The completed form is shown in Figure 22.7. Before you set other object properties, you first need to set the ADO Data controls properties, to connect it to the Customers table in the GRAPEVINE database. The ConnectionString property is set first. Select the ADO Data control, select the ConnectionString property in the Properties window, and then click on the button with the three dots. Visual Basic displays the General tab of the controls Property Pages dialog box, as shown in Figure 22.8.
Three ways exist to specify the connection between the control and a database. You will use a Connection String. Select the option for Connection String and then click on the Build button. After you are familiar with database programming, you may be able to write the connection string from scratch, but for now, let Visual Basic help you. The Data Link Properties dialog box is displayed. This dialog box has several tabs on it; the Connection tab is shown in Figure 22.9. Heres what you need to do:
When finished, click on OK. The connection string is entered into the Property Page. Click on OK again to accept this as the ADO Data controls ConnectionString property. The next property of the ADO Data control that you need to set is RecordSource. This property is the statement, usually expressed in SQL, that specifies which records are to be returned by the control. The specification includes both the table name and a criterion for records to be returned from that table. The statement you use is the following: select * from customers This is a very simple SQL statement that says, when translated into English, select all records from the customers table. To enter this property, display the property page for the RecordSource property (Figure 22.10) and select 1 - adCmdText as the command type. Then, enter the preceding SQL statement in the Command text (SQL) box, and click on OK.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |