Microsoft KB Archive/304724

= ACC2002: How to Return an ADO Recordset from a RecordsetDef on a Data Access Page =

Article ID: 304724

Article Last Modified on 9/27/2006

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



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.

 Open the Northwind sample database. In the Database window, click Pages under Objects, and then click New to create a new data access page. 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. Save the new page as Customers.htm . Open the Customers page in Design view, and then add a command button to the header section of the Customers page. In the property sheet for the command button, change the InnerText property to View with ADO .</li> Save the page.</li> On the Tools menu, point to Macro, and then click Microsoft Script Editor.</li> On the View menu, point to Other Windows, and then click Document Outline.</li>  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> </li>  Copy and paste the following VB script between the  markers. Dim rs Dim rsDef Dim LoopCnt

LoopCnt = 0 rsDef = MSODSC.RecordsetDefs.Item(0).Name Set Rs = MSODSC.Execute(strRecordsetDef)

Rs.MoveFirst MsgBox &quot;Company: &quot; & Rs(&quot;CompanyName&quot;) & vbNewLine & &quot;Contact: &quot; & Rs(&quot;ContactName&quot;) & _ vbNewLine & &quot;Phone: &quot; & Rs(&quot;Phone&quot;)

Set Rs = Nothing </li> Save your changes to Customers.htm, and then preview the data access page.</li></ol>

<div class="references_section">