Example

Loading Recordsets using DGrid for ADO.

NOTE: Recorsets must have a primary index, be scrollable, and bookmarkable.  For best results set the LockType to adLockOptimistic, the CursorLocation to adUseServer, and CursorType to adOpenKeyset.

DGrid for ADO requires a reference to "Microsoft ActiveX Objects 2.5 Library". 


With a Data Control

The following example loads a recordset using a Data Control. This example assumes there is a data control named Adodc1 and a DGrid control named ADGrid1 sited on the form.


Option Explicit

Private Sub Form_Load()
    Adodc1.Visible = False
    Adodc1.Refresh
    ADGrid1.LoadRecords Adodc1.Recordset
End Sub

Private Sub Form_Resize()
    ADGrid1.Top = 0
    ADGrid1.Left = 0
    ADGrid1.Width = Me.ScaleWidth
    ADGrid1.Height = Me.ScaleHeight
End Sub

Without a Data Control

The following example loads a recordset without using a Data Control.  This example assumes you have a DGrid control named ADGrid1 sited on the form and have added a reference to the "Microsoft ActiveX Data Objects 2.5 Library".


Option Explicit

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Private Sub Form_Load()
    Set cn = New Connection
    Set rs = New Recordset
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=YourDatabase.mdb"
    cn.Open
    rs.LockType = adLockOptimistic
    rs.CursorLocation = adUseServer
    rs.Open "Select * From YourTable Order By YourField", cn, adOpenKeyset
    ADGrid1.LoadRecords rs
End Sub

Private Sub Form_Resize()
    ADGrid1.Top = 0
    ADGrid1.Left = 0
    ADGrid1.Width = Me.ScaleWidth
    ADGrid1.Height = Me.ScaleHeight
End Sub

Private Sub Form_Unload(Cancel As Integer)
    rs.Close
    cn.Close
End Sub