ACC2002: Connection Property of the DSCEventInfo Object Does Not Work (295060)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q295060
Advanced: Requires expert coding, interoperability, and multiuser skills.

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

SYMPTOMS

In the Help system for the Microsoft Script Editor, the Connection property of the DSCEventInfo object is described as a property that returns an ADO connection object. However, a variable set equal to this Connection property does not produce a connection object, and it can cause a run-time error.

RESOLUTION

Use standard ADO syntax to create the connection object. The following steps illustrate how to create a connection object.

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

  1. Start Access, and then open the sample database Northwind.mdb.
  2. Click Pages in the Database window, and then open the Employees page in Design view.
  3. On the Tools menu, point to Macro, and then click Microsoft Script Editor.
  4. In the Microsoft Script Editor, click the arrow in Object box, and then click MSODSC in the drop-down list.
  5. Click the arrow in the Event box, and then click DataPageComplete in the drop-down list to insert the DataPage Complete script event.
  6. Modify the script event as follows:
    <SCRIPT event=DataPageComplete(objDSCEventInfo) for=MSODSC language=vbscript>
     <!--
      On Error Resume Next
      
      Dim objConnection
      
      Set objConnection = CreateObject("ADODB.Connection")  
      
      objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                         "Data Source=C:\Program Files\Microsoft Office\Office10\Samples\Northwind.mdb;"
      
      If Err.number <> 0 Then
          MsgBox "Error #" & Err.number & ": " & Err.description
          Err.Clear
      End If
     -->
    </SCRIPT>
    						
  7. On the File menu, click Save, and on the File menu again, click Exit to return to Microsoft Access.
  8. On the View menu, click Page View. Note that the page opens as expected.

    If you are using an Access project, you must change the objConnection.Open command line above to syntax similar to
      objConnection.Open "Provider=SQLOLEDB.1;" & _
                         "Data Source=<ServerName>;" & _
                         "User ID=<UserName>;" & _
                         "Initial Catalog=<DatabaseName>"
    						
    where <ServerName> should be replaced by the name of your SQL Server or MSDE computer, <UserName> should be replaced by a valid user account name, such as "sa", and <DatabaseName> should be replaced by the name of the SQL Server or MSDE source, such as NorthwindCS.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

In the Help system for the Microsoft Script Editor, the Connection property of the DSCEventInfo object is described as follows:

Returns or sets the ADO Connection object used by the specified object. Read/write for the PivotTable object; read-only for the DataSourceControl and DSCEventInfo objects.

expression.Connection
					
expression Required. An expression that returns one of the objects in the Applies To list (i.e. DSCEventInfo Object, DataSourceControl Object, PivotTable Object).

However, a variable that is set to the Connection property fails, usually silently, and can generate a run-time error when you try to use the connection object at some later point.

The following steps illustrate this behavior. Because the creation of the connection object fails silently, a user-defined error handler has been included to trap for the failure.

Steps to Reproduce the Behavior

  1. Start Access, and then open the sample database Northwind.mdb.
  2. Click Pages in the Database window, and then open the Employees page in Design view.
  3. On the Tools menu, point to Macro, and click Microsoft Script Editor.
  4. In the Microsoft Script Editor, click the arrow in Object box, and then click MSODSC in the drop-down list.
  5. Click the arrow in the Event box, and then click DataPageComplete in the drop-down list to insert the DataPage Complete script event.
  6. Modify the script event as follows:
    <SCRIPT event=DataPageComplete(objDSCEventInfo) for=MSODSC language=vbscript>
     <!--
      On Error Resume Next
      
      Dim objConnection
      
      Set objConnection = objDSCEventInfo.Connection
    
      objConnection.Open
      
      If Err.number <> 0 Then
          MsgBox "Error #" & Err.number & ": " & Err.description
          Err.Clear
      End If
     -->
    </SCRIPT>
    						
  7. On the File menu, click Save, and on the File menu again, click Exit to return to Microsoft Access.
  8. On the View menu, click Page View. Note that you receive the following error message:
    Error #424: Object required

REFERENCES

For more information about the Connection property, click Microsoft Script Editor Help on the Help menu, type Connection Property in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about the DSCEventInfo object, click Microsoft Script Editor Help on the Help menu, type DSCEventInfo in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Modification Type:MajorLast Reviewed:11/6/2003
Keywords:DAPScriptProb kbbug kbDAPScript kbdocerr kbdta kbnofix KB295060