Option Explicit
Private dbConn As ADODB.Connection
Private Rst As ADODB.Recordset
Private Sub Form_Load()
Set dbConn = CreateObject("ADODB.Connection")
Dim conString As String
conString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=D:\mdb\Northwind.mdb"
dbConn.ConnectionString = conString
dbConn.Open
Set Rst = CreateObject("ADODB.Recordset")
Rst.CursorLocation = adUseClient
Dim sql As String
sql = "select * from orders"
Rst.Open sql, dbConn, adOpenKeyset, adLockPessimistic, adCmdText
Set DataGrid1.DataSource = Rst
Set Text1.DataSource = Rst
Text1.DataField = "OrderID"
Set Text2.DataSource = Rst
Text2.DataField = "ShipName"
Set Text3.DataSource = Rst
Text3.DataField = "ShipCity"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set Rst = Nothing
Set dbConn = Nothing
End Sub