How can a record set be used to populate a dbgrid control.
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
Re: How can a record set be used to populate a dbgrid control.
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
Re: How can a record set be used to populate a dbgrid control.
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
Re: How can a record set be used to populate a dbgrid control.
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
Re: How can a record set be used to populate a dbgrid control.
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
Re: How can a record set be used to populate a dbgrid control.
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.
Re: How can a record set be used to populate a dbgrid control.
Yes, that way it works
Thanx
Also which is the best way to clear the records from a dbgrid control.
Regards
Aswin Asokan