Augmenting Data Access Pages with VBScript
One of the powers of data access pages is in the capability to customize them beyond what the data access page designer allows. The MSE allows you to create scripts that extend the functionality of your data access pages. Using the MSE, you create scripts behind the events of objects on the data access page.To open the MSE and create a script behind a data access page, follow these steps:
Figure 26.41. Using the Toolbox, you can add controls to your data access page.

Figure 26.42. The Microsoft Script Editor allows you to write code in response to events generated within your data access pages.

Figure 26.43. The HTML window allows you to select an object and an event associated with the object.

Figure 26.44. VBScript code that displays the message "Hello" when the onclick event of the cmdSayHello command button occurs.

Important Data Access Page Events
As you have seen, scripts included for data access pages are written in event handlers attached to objects on a page. As in an Access form, an event handler (or event routine) is a subroutine or function that is automatically triggered in response to something happening to an object. Some important events that you can code at the document (page) level include the following:
- The OnRowEnter event of the Document object fires after the current record changes but before fields are populated for the new record.
- The OnRowExit event of the Document object occurs before the current record changes. This event is commonly used to perform record-level validations.
- The BeforeCollapse event of a section occurs before the section is collapsed.
- The BeforeExpand event of a section occurs before a section is expanded.
- The BeforeNextPage, BeforePreviousPage, BeforeFirstPage, and BeforeLastPage events of the page navigation control occur before the navigation control navigates to the next, previous, first, and last pages, respectively. You can cancel all these events by setting the info.return value of the event to False.
- The Current event fires after a section becomes the current section.
- The DataPageComplete event fires when all data binding is completed after a page open, navigation, or expansion.
As with the events of a form or a report, it is important to explore and learn about the events of a page so that you know where to place your code.
VBScript Versus VBA
Because Internet Explorer 5.0 cannot interpret Visual Basic for Applications (VBA), scripts that you write must be in the VBScript language. VBScript is a subset of the VBA language. The following are important differences between VBA and VBScript that you should be aware of:
- All variables are variants in VBScript. This means that Dim statements in VBScript cannot include types.
- Arguments (parameters) to subroutines and functions in VBScript cannot have types.
- Many built-in functions available in VBA are not available in VBScript.
- Intrinsic constants such as vbYesNo are not available in VBScript. If you want to include constants in your code, you will have to declare them yourself.
VBScript Versus JavaScript
Scripts that you write behind your data access pages can be written in either VBScript or in JavaScript/JScript. If you are accustomed to writing VBA code, you will probably find VBScript much easier to learn than JavaScript. On the other hand, if you are experienced at developing Web pages using JavaScript, you will probably want to continue writing your scripts in JavaScript/JScript. The following are some important differences between VBScript and JavaScript/JScript:
- VBScript is better supported by the data access page object model. This means that certain page events are not recognized if coded in JavaScript.
- JavaScript/JScript is case-sensitive, making it more difficult to write than VBScript.