Address Book Command Buttons

The Address Book application includes the following command buttons:

Find Button

The following HTML statement defines the Find button. This HTML statement appears before the VBScript section of the program. Copy and past this control just following the Comment for HTML Command Buttons.

<INPUT TYPE=BUTTON NAME="Find" 	VALUE="Find">

Find_OnClick Sub Procedure

Clicking the Find button activates the VBScript Find_OnClick Sub procedure, which builds and sends the SQL query. When you complete the project click this button to fill the data grid.

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. Copy and paste this code beneath the opening <Script> tag.

Sub Find_OnClick

myQuery = "Select FirstName, LastName, Title, Type, Email, " _
	& "ManagerEmail, Building, Room, Phone from Employee"

Next, the Sub procedure scans each of the four input boxes of the Address Book. Copy and paste this code within the Find sub routine.

	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

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%'

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 RDSIE3.DataControl object equal to the dynamically built SQL query. The second statement causes the RDSIE3.DataControl object (SControl) to query the database, and then display the new results of the query in the grid. Copy and paste this code to the Find subroutine.

	SControl.SQL = myQuery
	SControl.Refresh
End Sub

Clear Button

The following HTML statement defines the Clear button. This HTML statement appears before the VBScript section of the program. Copy and paste this code just following the Find HTML button.

<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.

Clear_OnClick Sub Procedure

Clicking the Clear button activates the VBScript Clear_OnClick Sub procedure. Copy and paste this code within the <Script> </Script> tags.

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.

Update Profile Button

The following code defines the Update Profile button. This HTML statement appears before the VBScript section of the program. Copy and paste this HTML control just following the Clear button.

<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).

Update_OnClick Sub Procedure

Clicking the Update Profile button activates the VBScript Update_OnClick Sub procedure, which executes the RDSIE3.DataControl object's (SControl) SubmitChanges and Refresh methods. Copy and paste this code within the <Script> </Script> tags.

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 isn't necessary after SubmitChanges with Remote Data Service 1.5, but it ensures the data is fresh.

Cancel Changes Button

The following code defines the Cancel Changes button. This HTML statement appears before the VBScript section of the program. Copy and paste this HTML control just following the Update button.

<INPUT TYPE=BUTTON NAME="Cancel" 	VALUE="Cancel Changes">

Cancel_OnClick Sub Procedure

Clicking Cancel Changes activates the VBScript Cancel_OnClick Sub procedure, which executes the RDSIE3.DataControl object's (SControl) CancelUpdate method. Copy and paste this code within the <Script> </Script> tags.

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.