The Address Book application includes the following command buttons:
The following HTML statement defines the Find button. This HTML statement appears before the VBScript section of the program.
<INPUT TYPE=BUTTON NAME="Find" VALUE="Find">
Clicking the Find button activates the VBScript Find_OnClick Sub procedure, which builds and sends the SQL query.
Building the SQL Query
The first part of the Find_OnClick Sub procedure builds the SQL query, a phrase at a time, by appending text strings to a global SQL SELECT statement. It begins by setting the variable myQuery to an SQL SELECT statement that requests all rows of data from the data source table:
Sub Find_OnClick myQuery = "Select FirstName, LastName, Title, Email," _ & " Building, Room, Phone from Employee"
Next, the Sub procedure scans each of the four input boxes of the Address Book:
If (SFirst.Value <> "") Then myQuery = myQuery + " where FirstName like '" + SFirst.Value + "%'" End If IF (SLast.Value <> "") Then myQuery = myQuery + " where LastName like '" + SLast.Value + "%'" End If If (STitle.Value <> "") Then myQuery = myQuery + " where Title like '" + STitle.Value + "%'" End If If (SEmail.Value <> "") Then myQuery = myQuery + " where Email like '" + SEmail.Value + "%'" End If myQuery = myQuery + " for browse" 'Mark recordset for editing.
Each If statement scans its corresponding text box for text. If the text box contains text, the Then statement executes, appending the quoted text to the global SELECT statement contained in the variable myQuery. Because the program uses the word like in building the SQL statements, the queries are substring searches rather than exact matches.
For example, if the Last Name box contained the entry "Berge" and the Title box contained the entry "Program Manager", the SQL statement (value of myQuery) would read:
Select FirstName, LastName, Title, Email, Building, Room, Phone from Employee where lastname like 'Berge%' and title like 'program manager%' and email for browse
If the query was successful, all persons with a last name containing the text "Berge" (such as Berge and Berger), with a title containing the words "Program Manager" (for example, Program Manager, Advanced Technologies) are displayed in the data grid.
Preparing and Sending the Query
The last part of the Find_OnClick Sub procedure consists of two statements. The first statement assigns the SQL query property of the AdvancedDataControl object equal to the dynamically built SQL query. The second statement causes the AdvancedDataControl object (SControl) to query the database, and then display the new results of the query in the grid.
SControl.SQL = myQuery SControl.Refresh End Sub
The following HTML statement defines the Clear button. This HTML statement appears before the VBScript section of the program.
<INPUT TYPE=BUTTON NAME="Clear" VALUE="Clear">
The INPUT tag defines an element, such as a button, option button, check box, or text. You use the TYPE parameter to specify the element, which in this case, is a button. The NAME parameter defines what the button will be called in code. The VALUE parameter specifies the labels associated with the button (Clear) that will be displayed on the page.
Clicking the Clear button activates the VBScript Clear_OnClick Sub procedure:
Sub Clear_OnClick SFirst.Value="" SLast.Value="" STitle.Value="" SEmail.Value="" End Sub
When the Sub procedure is executed, it initializes each of the four HTML input boxes, which it identifies by the NAME parameter of the ID tag. The property .Value indicates characters in the text box object that are displayed on the Web page. The procedure replaces any text with a zero length string ("") in preparation for a new find.
The following code defines the Update Profile button. This HTML statement appears before the VBScript section of the program.
<INPUT TYPE=BUTTON NAME="Update" VALUE="Update Profile">
The INPUT tag defines an element, such as a button, option button, check box, or text. The NAME parameter defines what the button will be called in code. You use the TYPE parameter to specify the type of form element, which in this case, is a button. The VALUE parameter specifies the label associated with the button (Update Profile).
Clicking the Update Profile button activates the VBScript Update_OnClick Sub procedure, which executes the AdvancedDataControl object's (SControl) SubmitChanges and Refresh methods:
Sub Update_OnClick SControl.SubmitChanges SControl.Refresh End Sub
When SControl.SubmitChanges executes, the program packages all the update information and sends it to the server via HTTP. The update is all-or-nothing; if a part of the update isn't successful, none of the changes are made, and a status message is returned. SControl.Refresh requeries the database so the grid is refreshed with new data. It is important to do this because it allows subsequent edits and saves.
The following code defines the Cancel Changes button. This HTML statement appears before the VBScript section of the program.
<INPUT TYPE=BUTTON NAME="Cancel" VALUE="Cancel Changes">
Clicking Cancel Changes activates the VBScript Cancel_OnClick Sub procedure, which executes the AdvancedDataControl object's (SControl) CancelUpdate method:
Sub Cancel_OnClick SControl.CancelUpdate End Sub
When SControl.CancelUpdate executes, it discards any edits that a user has made to an employee record on the data grid since the last query or update. It restores the original values.
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.