Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to Populate DataGrid with ADO.....Assistance Please

Status
Not open for further replies.

pewilson

Technical User
Mar 9, 2001
52
US
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
 
Hiya,

put some error handling in to check whether your connection is actually active after you've made it. Also, check that your recordset is actually returning something - check it's not at EOF straight away after you've opened it.

I've only briefly looked at using datagrid controls, so I may have this wrong, but it looks to me that, if you're going to set a datagrid control's datasource at runtime, you have to use the datagrid.refresh method to display that data. I've only seen mention of this in relation to changing the datasource at runtime, but I would imagine the same applies if you intend to change from no datasource to any arbitary datasource.

See if that helps.

Paul
 
Here is my code works ok

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



Private Sub BINDDATA()
Set Text1.DataSource = rs
Set Text2.DataSource = rs
Text1.DataField = "VendorName"
Text2.DataField = "CareTakerIDNumber"
End Sub


Private Sub GETHOMEDATA()
If HD.State <> adStateClosed Then
HD.Close
End If
HD.ActiveConnection = cn
HD.LockType = adLockBatchOptimistic
HD.CursorLocation = adUseClient
HD.CursorType = adOpenDynamic
HD.Source = &quot;SELECT W_LASTNAME,W_FIRSTNAM,Firstday,BirthDay FROM Children WHERE CateTakerIDNumber = '&quot; & rs.Fields(13).Value & &quot;' ORDER BY W_LASTNAME&quot;
HD.Open
Set Inhouse.DataSource = HD

End Sub

Private Sub exit_Click()
Form6.Hide
Unload Form6
Form2.Show
End Sub

Private Sub Form_Load()
Dim strmove
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
Set HD = New ADODB.Recordset
strmove = Form2.Data1.Recordset.Fields(3).name & &quot;='&quot; & Form2.Data1.Recordset.Fields(3).Value & &quot;'&quot;
ISDIRTY = False
cn.ConnectionString = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source = \\fss45fc1\projects\fssa-gary\fiscal\Foster Home\Children.mdb&quot;
cn.Open
rs.ActiveConnection = cn
rs.LockType = adLockBatchOptimistic
rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic
rs.Source = &quot;select * from Vendor order by Vendorname&quot;
rs.Open
rs.Find strmove, 0, adSearchForward

BINDDATA
GETHOMEDATA
End Sub

Private Sub Form_Unload(Cancel As Integer)
HD.Close
Set HD = Nothing
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top