Microsoft KB Archive/203125

= ACC2000: ExecScript Method Executes Twice When You Scroll Through Records =

Article ID: 203125

Article Last Modified on 6/24/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q203125



This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

Moderate: Requires basic macro, coding, and interoperability skills.



SYMPTOMS
When you scroll through records on a data access page, the execScript method calls the expression twice.



CAUSE
The execScript method executes before you move off the current record, and then executes again after you arrive at the next record.



RESOLUTION
To ensure that the script executes only once, create a Boolean variable and toggle its value depending on whether the script has executed or not.

In the following sample resolution, a Boolean variable is dimensioned. The first time that the script executes, a message box appears, and the Boolean variable is then set to True to indicate that the script has executed. The second time that the script executes, because the value is now True, it skips the first part of the If statement and only resets the variable to False for the next record.

To see how this works, follow these steps:  Open the sample database, Northwind.mdb. In the Database window, click Pages under Objects, and then click New. In the New Data Access Page dialog box, click Page Wizard, click Shippers in the Choose the table or query where the object's data comes from box, and then click OK. Click the >> button to move all the fields from the Available Fields list to the Selected Fields list. Click Finish. Add an unbound text box to the Header: Shippers section.  In the properties sheet, click the Data tab, and then set the ControlSource property of the unbound text box to the following: Expr1: document.parentWindow.execScript("subTest","VBScript") </li> On the Tools menu, point to Macro, and then click Microsoft Script Editor.</li> On the HTML menu, point to Script Block, and then click Client.</li>  Type the following: <SCRIPT language=vbscript>

</SCRIPT> </li> Press ALT+TAB to switch back to the Microsoft Access.</li> On the View menu, click Page View and note that as you scroll through the records, the message box appears twice for each record.</li></ol>

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in Microsoft Access 2000.

<div class="moreinformation_section">

Steps to Reproduce the Behavior
<ol> Follow steps 1 through 7 in the "Resolution" section.</li>  Type the following: <SCRIPT language=vbscript>

</SCRIPT> </li> Follow steps 9 through 10 in the Resolution section.</li></ol>

<div class="references_section">

Explanation of the execScript Method
Executes the specified script in the provided language.

Syntax: window.execScript(sExpression, sLanguage) Parameters:

sExpression: Required. String that specifies the code to be executed.

sLanguage: Required. String that specifies the language in which the code is executed. The language defaults to Microsoft JScript.

Return Value:

No return value.

Additional query words: pra

Keywords: kbbug kbdap kbpending kbdapscript KB203125

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.