I have a form with ADO code and when on load, the customer data should populate the DataGrid. However, when I go to run it, the DataGrid is empty. Any suggestions?
All the help will be greatly appreciated.
Paul
Here is the Code:
Private Sub Form_Load()
Dim rsLoadCustomer As ADODB.Recordset
Dim cnLoadCustomer As ADODB.Connection
Dim strSQL As String
strSQL = "Select * from Customers"
Set rsLoadCustomer = New ADODB.Recordset
Set cnLoadCustomer = New ADODB.Connection
With cnLoadCustomer
.Provider = " Microsoft.Jet.OLEDB.4.0 "
.ConnectionString = "Data Source =" & App.Path & "\Customerservice.mdb;"
.Open
End With
With rsLoadCustomer
.CursorLocation = adUseClient
.LockType = adLockPessimistic
.Open strSQL, cnLoadCustomer
End With
Set DataGrid1.DataSource = rsLoadCustomer
rsLoadCustomer.Close
Set rsLoadCustomer = Nothing
cnLoadCustomer.Close
Set cnLoadCustomer = Nothing
End Sub
All the help will be greatly appreciated.
Paul
Here is the Code:
Private Sub Form_Load()
Dim rsLoadCustomer As ADODB.Recordset
Dim cnLoadCustomer As ADODB.Connection
Dim strSQL As String
strSQL = "Select * from Customers"
Set rsLoadCustomer = New ADODB.Recordset
Set cnLoadCustomer = New ADODB.Connection
With cnLoadCustomer
.Provider = " Microsoft.Jet.OLEDB.4.0 "
.ConnectionString = "Data Source =" & App.Path & "\Customerservice.mdb;"
.Open
End With
With rsLoadCustomer
.CursorLocation = adUseClient
.LockType = adLockPessimistic
.Open strSQL, cnLoadCustomer
End With
Set DataGrid1.DataSource = rsLoadCustomer
rsLoadCustomer.Close
Set rsLoadCustomer = Nothing
cnLoadCustomer.Close
Set cnLoadCustomer = Nothing
End Sub