Discussion Locked

DAO Recordset and Data Control

0 helpful
13 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

What is the best method to connect a recordset object in code to a DBGrid?

If I have to use the DataControl then fine, (I believe that this has to be done this way with DAO) - but only to connect to the grid. I do not want to have to set any properties of the DataControl or use it to manipulate through the records - I want to use a plain old recordset object to do all of that but still have it update the records in the grid!

(I have to work on a program that was created with all bound DBGrids and uses DAO and do not want to take the effort right now to change it all over to ADO)

13 replies

by glen_mcleod

You don't have to use a DC.

Declare a class or form level variable as DAO.Recordset, this will let it stay open as long as the form or class is alive.

Open your recordset the normal way, then assign it to the RecordSource (DataSource?) property of your grid using code:

Set DBGrid1.RecordSource = m_rsGridData

(forgive me, I don't work with bound controls that much, and I can't remember the exact property name).

Just remember to close and set to Nothing your Recordset objects in the terminate event of your class or form.

Glen

by c1980

For Answer #1:
I am afraid that this is not working for me. I know how to handle classes, recordsets, and use my own data enviroment classes.

The problem is that setting the datasource of a DBGrid control, (Not an ADO datagrid control), to a DAO recordset doesn't seem to be supported by the DBGrid control at run time as is the ADO GridControl. I am only able to set the recordsource to a DataControl in the IDE. Therefore I said that I believe the only way is to use the datacontrol and therefore, my question is, if this is so, how can I still manipulate everything via my recordset, (without setting properties or using the methods of the datacontrol except for maybe setting the datasource).

I will raise the points and also leave youranswer unrated for a few days incase you have more ideas, not wanting to reject it right away....

by donq

I base all of me forms on a query AND use a list box on each form to replace the data control for record navigation. My forms are all DAO (only) and the data control is not even displayed. On the Toolbox click Combo Box and place it on your form -then select "Find a record on my form based on the value I select"., then select a UNIQUE field common to the form and combo box.

by c1980

Sorry, I thought that it would have been clear that I was using VB6, not Access by using the terms DataGrid, DataControl, DBGrid, IDE.
anyways, it sounds like the objects you use are still bound, which is not what I want.
I know that this could be changed but still, I need to use a DBGrid to display the records. If I change the DBGrid for something else, then I might as well go all the way and change to ADO to solve my problem, even though ADO is slower when used on a MDB. And a ListBoxis not efficient, (speed and system resources), for handling 100,000 records - it will bomb out - it is only good for up to about 1000 records, (of course depending on the number of fields).

by c1980

For Answer #2:

Sorry, I hit the button too fast. I wanted to also leave your answer open in case you came up with something else......Anyways, your response is appreciated!

by c1980

Ok. I am going to close this in a few days. If someone is working on an answer then e-mail me and I will wait before closing......Looks like I am stuck with using the DataControl in VB6 and DAO for the DBGrid /:(

by sl-campbell

Ok. I've let you smore long enough, (remember?)

Unfortunately, you MUST use the datacontrol. But you CAN set a recordset object to the datacontrol in DAO with-out having to set any other properties. Not too many people know how to do this, and a while back it took me a sometime to figure it out, but it is very simple. First, you do not set the RecordSource, (as I tried to). You SET the datacontrol's recordset OBJECT to YOUR recordset object! You do not have to do anything else - not even setthe database or connection properties - it will take on the identical properties as your rs object.
Then all repositioning, methods, etc, that you use on your recorset object will affect the datacontrol's rs and in turn the DBGrid, even additions and deletions. The only thing that you need to do extra is re-set it again if you re-open the recordset, (like after changing the SELECT statement when changing criteria or sort order - if you cannot use the sort/filter methods of the recordset because it is not a Jet Db).

It's the best that can be done with-out using the grid in unbound mode( alot of work).

Ok? Ok!

by shanghai sam

You brat! You could have told me that the other day, then I wouldn't have needed to spend the points! But I know - it's your game.
Anyways, it does work......I guess anything better would mean changing to ADO, using the ActiveX Grids that go along with it, or buying a different third party grid.

This discussion is closed to new replies.