ACC2000: ExecScript Method Executes Twice When You Scroll Through Records (203125)



The information in this article applies to:

  • Microsoft Access 2000

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:
  1. Open the sample database, Northwind.mdb.
  2. In the Database window, click Pages under Objects, and then click New.
  3. 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.
  4. Click the >> button to move all the fields from the Available Fields list to the Selected Fields list. Click Finish.
  5. Add an unbound text box to the Header: Shippers section.
  6. 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")
    					
  7. On the Tools menu, point to Macro, and then click Microsoft Script Editor.
  8. On the HTML menu, point to Script Block, and then click Client.
  9. Type the following:
    <SCRIPT language=vbscript>
    <!--
    Dim blnVar
    
    Sub subTest()
    
       If Not blnVar Then
          MsgBox "Testing"
          blnVar = True
       Else
          blnVar = False
       End If
    
    End Sub
    -->
    </SCRIPT>
    					
  10. Press ALT+TAB to switch back to the Microsoft Access.
  11. On the View menu, click Page View and note that as you scroll through the records, the message box appears twice for each record.

STATUS

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

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Follow steps 1 through 7 in the "Resolution" section.
  2. Type the following:
    <SCRIPT language=vbscript>
    <!--
    Sub subTest()
    	MsgBox "Testing"
    End Sub
    -->
    </SCRIPT>
    					
  3. Follow steps 9 through 10 in the Resolution section.

REFERENCES

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.


Modification Type:MajorLast Reviewed:6/24/2004
Keywords:kbbug kbDAP kbDAPScript kbpending KB203125