Binding a Page to a Disconnected Recordset
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
Meyyammai Subramanian
Microsoft Corporation
April 2001
Applies to:
Microsoft® Access 2002
Summary: This article explains how to bind a data access page to a disconnected ADO recordset. (3 printed pages)
Contents
Introduction
Create a Page that Uses a Disconnected Recordset
Introduction
A disconnected recordset is an object in a client cache that does not have a live connection to the server. Using disconnected recordsets, ActiveX® Data Objects (ADO) allows you to create a recordset, disconnect from the data source, and let the user view and edit the recordset offline.
For example, the Categories data access page asks whether the page should use disconnected data. If the user clicks Yes, the page prompts the user to enter the path to the disconnected recordset. If the user clicks No, the page uses live data.
Create a Page that Uses a Disconnected Recordset
Create a data access page in Design view.
Add the desired controls and group levels. For example, create a Categories page which groups Product records under different categories.
Add code to the BeforeInitialBind event to connect either to a disconnected recordset or to live data.
The following is a sample BeforeInitialBind event procedure.
<SCRIPT language=vbscript event=BeforeInitialBind(info) for=MSODSC> <!-- Dim rs Dim strShapeText Dim strConnectionString Dim strDataSource adOpenKeyset=1 adLockOptimistic=3 If vbyes=msgbox("Use disconnected recordset?",vbyesno) Then On Error Resume Next strDataSource = InputBox ("Please enter the path to the _ disconnected recordset to use.", "Enter Path", _ "C:\Program Files\Microsoft Office\Office10\Samples\ _ Northwind.mdb") strShapeText = MSODSC.RootRecordsetDefs(0).ShapeText strConnectionString = "Provider=MSDataShape.1; _ Persist Security Info=False;Data Source=" & strDataSource _ & ";User ID=Admin;Data Provider=Microsoft.Jet.OLEDB.4.0" Set rs = CreateObject("ADODB.Recordset") rs.Open strShapeText, strConnectionString, adOpenKeyset, _ adLockOptimistic If err.Number <> 0 Then MsgBox "Error: " & err.description & "Error " & err.number End If MSODSC.SetRootRecordset "Categories", rs End If --> </SCRIPT>
Notes
A page that binds to a disconnected recordset will not work properly from within Microsoft Access. Open the page in Microsoft Internet Explorer to view the page properly.
When you create Visual Basic® Scripting Edition (VBScript) blocks for Microsoft® Office Data Source Control (MSODSC) events, you must add a parameter to the event name as follows:
<SCRIPT LANGUAGE=vbscript FOR=MSODSC EVENT=Current(oEventInfo)>
The oEventInfo parameter is used to return specific information about the event to the script. You must add this parameter, whether or not it will be used, because the script won't work without it.