Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: ExecScript Method Executes Twice When You Scroll Through Records


View products that this article applies to.

Symptoms

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

↑ Back to the top


Cause

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

↑ Back to the top


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.

↑ Back to the top


Status

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

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


Keywords: KB203125, kbdapscript, kbpending, kbdap, kbbug

↑ Back to the top

Article Info
Article ID : 203125
Revision : 2
Created on : 6/24/2004
Published on : 6/24/2004
Exists online : False
Views : 222