Skip to content

Latest commit

 

History

History
40 lines (33 loc) · 1.28 KB

bind-a-form-to-an-ado-recordset.md

File metadata and controls

40 lines (33 loc) · 1.28 KB
title ms.assetid ms.date ms.localizationpriority
Bind a form to an ADO Recordset
de85b07c-aa2d-7cf6-e0da-70b682f1bdd0
09/21/2018
medium

Bind a form to an ADO Recordset

To bind an Access form to a recordset, you must set the form's Recordset property to an open ADO Recordset object. A form must meet two general requirements for the form to be updatable when it is bound to an ADO recordset. The general requirements are:

  • The underlying ADO recordset must be updatable via ADO.
  • The recordset must contain one or more fields that are uniquely indexed, such as a table's primary key.
 Private Sub Form_Open(Cancel As Integer) 
 Dim cn As ADODB.Connection 
 Dim rs As ADODB.Recordset 
 
 'Use the ADO connection that Access uses 
 Set cn = CurrentProject.AccessConnection 
 'Create an instance of the ADO Recordset class, 
 'and set its properties 
 Set rs = New ADODB.Recordset 
 With rs 
 Set .ActiveConnection = cn 
 .Source = "SELECT * FROM Customers" 
 .LockType = adLockOptimistic 
 .CursorType = adOpenKeyset 
 .Open 
 End With 
 'Set the form's Recordset property to the ADO recordset 
 Set Me.Recordset = rs 
 Set rs = Nothing 
 Set cn = Nothing 
End Sub

[!includeSupport and feedback]