Click to See Complete Forum and Search --> : How can a record set be used to populate a dbgrid control.


aswinasokan
July 11th, 2000, 01:55 AM
How can a record set be used to populate a dbgrid control.

My code is
Dim rs As Recordset
Dim db As Database
...
...
Set rs = db.OpenRecordset(strQuery, dbOpenDynaset)

I need to display the records returned in rs onto the grid???



Regards
Aswin Asokan

Johnny101
July 11th, 2000, 09:44 AM
Set the datasource property of the grid equal to the recordset:


Dim rs as Recordset
Dim db as Database
...
...
set rs = db.OpenRecordset(strQuery, dbOpenDynaset)

set DBGrid1.DataSource = rs
DBGrid1.Refresh




i'm pretty sure you can do that with DAO.

Hope this helps,

John

John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org

aswinasokan
July 11th, 2000, 11:59 PM
set DBGrid1.DataSource = rs
gives an error on that line

Run-time error '430':
Class does not support Automation or does not support expected interface

Regards
Aswin Asokan

Lothar Haensler
July 12th, 2000, 02:18 AM
you cannot directly assign anything useful to the datasource property.
But, you can use a data control and bindn your dbgrid to the data control.
Then, if "c" is your data control and "d" is your dbgrid:

Set rs = c.Database.OpenRecordset("select * from yourtable")
' assign to the recordset property OF THE DATA CONTROL
' this will automatically populate the DBGrid, because it's bound to the data control.
Set c.Recordset = rs

aswinasokan
July 13th, 2000, 01:00 AM
The code gave run time error :
Run-time error '91'
Object variable or With block variable not set

dataCall is a data control
gridResults is a dbgrid

Dim rs As Recordset
Set rs = dataCall.Database.OpenRecordset(strQuery) 'run time error
Set dataCall.Recordset = rs

I also tried
Dim db As Database
Dim rs As Recordset
Set rs = db.OpenRecordset(strQuery, dbOpenDynaset) 'run time error
Set dataCall.Recordset = rs

which again gave the same error

Regards
Aswin Asokan

Lothar Haensler
July 13th, 2000, 02:58 AM
well, your datacall object must have been initialised before you can apply a method like OpenRecordset to it.
Set the connect property and call the Refresh method before doing anything else.

aswinasokan
July 13th, 2000, 07:30 AM
Yes, that way it works
Thanx

Also which is the best way to clear the records from a dbgrid control.

Regards
Aswin Asokan