ACC2002: How to Return an ADO Recordset from a RecordsetDef on a Data Access Page (304724)



The information in this article applies to:

  • Microsoft Access 2002

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

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

SUMMARY

This article shows you how to use ActiveX Data Objects (ADO) to access the RecordsetDefs object of a data access page and to list its contents.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. 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. Open the Northwind sample database.
  2. In the Database window, click Pages under Objects, and then click New to create a new data access page.
  3. In the New Data Access Page dialog box, click AutoPage: Columnar, click the Customers table in the Choose the table or query where the object's data comes from box, and then click OK.
  4. Save the new page as Customers.htm.
  5. Open the Customers page in Design view, and then add a command button to the header section of the Customers page.
  6. In the property sheet for the command button, change the InnerText property to View with ADO.
  7. Save the page.
  8. On the Tools menu, point to Macro, and then click Microsoft Script Editor.
  9. On the View menu, point to Other Windows, and then click Document Outline.
  10. In the Document Outline window, expand the Client's Objects & Events folder, and then double-click the onclick event for the Command0 button. This will insert the VB Script that defines the onclick event for the Command0 button into the Customers.htm page. The inserted VB Script will look similar to the following:
    <SCRIPT language=vbscript event=onclick for=Command1>
    
    <!--
    
    -->
    
    </SCRIPT>
    					
  11. Copy and paste the following VB script between the <!-- and --> markers.
      Dim rs
      Dim rsDef
      Dim LoopCnt 
    
      LoopCnt = 0
      rsDef = MSODSC.RecordsetDefs.Item(0).Name 
      Set Rs = MSODSC.Execute(strRecordsetDef) 
    
      Rs.MoveFirst 
      MsgBox "Company: " & Rs("CompanyName") & vbNewLine & "Contact: " & Rs("ContactName") & _
     vbNewLine & "Phone: " & Rs("Phone") 
    
       Set Rs = Nothing 
    					
  12. Save your changes to Customers.htm, and then preview the data access page.

REFERENCES

For more information about RecordsetDefs, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type recordsetdefs in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Modification Type:MinorLast Reviewed:9/27/2006
Keywords:kbdta kbhowto KB304724