How to set a recordset as recordsource of form(from code)?

L

Lu An De

Hi all,

It is sometimes useful to create a recordset 'on the fly' in code using
code like this:

Dim rsClients as ADODB.Recordset
Set rsClients = New ADODB.Recordset
rsClients.Fields.Append "ClientID", adInteger
rsClients.Open

This recordset requires no tables nor queries to draw from. It can be added
to and filtered in code very easily.

Is there a way to apply this code generated recordset as the recordsource of
a form and have the user be able to view its rows?

Alternatively, how to save a recordset as a table or query(in code)?

Regards, Lu An De
 
M

MacDermott

You can set a form's Recordset property, for example in the form's Load
event procedure
Set Me.Recordset=rsClients
in all Access versions starting with Access 2000. (A97 did not expose the
Recordset property.)

Be aware, however, that a detached ADO recordset as a form's Recordset
property is not updatable.

As far as saving your recordset as a table goes (AFAIK, a query MUST be
based on a table), I think your best option is to create the table first,
then open an ADO (or DAO) recordset based on it, if you need to.

HTH
- Turtle
 
L

Lu An De

Thanks for your pointers Turtle,

I should be able to get a bit further now.

Lu An De.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top