Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] - نسخه متنی

Alison Balter

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



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:


  • Create a data access page.

  • Use the Toolbox tool on the toolbar to display the toolbox (see Figure 26.41).

    Figure 26.41. Using the Toolbox, you can add controls to your data access page.

  • Make sure that you click the Control Wizards tool in the Toolbox to deactivate the control wizards (the upper right-hand tool in the toolbox).

  • Add a control, such as a command button, to the data access page. Use the ID property to rename the control, such as cmdSayHello.

  • Right-click the control and select Microsoft Script Editor. The Microsoft Development Environment (MDE) appears (see Figure 26.42). If you did not install Web Scripting when you installed Microsoft Access, you will need to install it for this feature to be available.

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

  • Activate the HTML window (see Figure 26.43).

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

  • Use the object drop-down on the left of the HTML window to locate the object that you just added.

  • Use the event drop-down on the right of the HTML window to designate the event that you want to write code for. A script block is created with a stub for the object and event. In Figure 26.43, a script block is inserted for the onclick event of the command button called cmdSayHello.

  • Write code that executes in response to the event. In Figure 26.44, the MsgBox statement is used to display the message "Hello" when a user clicks the cmdSayHello command button.

    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.



    / 544