RecordSet and RecordSource

  • Thread starter Thread starter Smartin
  • Start date Start date
S

Smartin

Good Day All,

An easy one? If I have a RecordSet object, can I set a form's
RecordSource property using the RecordSet? How?

I feel like I am overlooking something obvious.
 
Smartin said:
Good Day All,

An easy one? If I have a RecordSet object, can I set a form's
RecordSource property using the RecordSet? How?

I feel like I am overlooking something obvious.

Sorry... using A97 and DAO recordset.
 
Create a new form. If you use the wizard, following the steps will set up
your form using the recordset of your choice. If not, in design view open
the properties for the form. The first item is "RecordSource". Select the
appropriate value.
 
Smartin said:
Good Day All,

An easy one? If I have a RecordSet object, can I set a form's
RecordSource property using the RecordSet? How?

I feel like I am overlooking something obvious.

Guess I need to provide a little more information:

The form's RecordSource is established on the fly in code, so I can't
"hard code" it into the form's properties.

RecordSet is not a property of "form" (at least, not in A97).

Here's more background. First I get some search terms from the user and
create a query statement. Next I create a RecordSet using the query. The
form's RecordSource will be set one of two ways depending on how many
records are in the RecordSet. So I was thinking to create the RecordSet
first, count the records, then set the form's RecordSource accordingly.

Alternatively I could skip the RecordSet and set the form's RecordSource
property using the constructed query and do some other things based on
how many records wind up in the form's "RecordSet". To do this I will
need a way to count the records, but I'm failing to figure out how this
is done either.

As it is I am currently getting the RecordSet with
Set RCD = CurrentDb.OpenRecordset(Query)

and then setting the form's RecordSource (sometimes) with
MyForm.RecordSet = Query

.... which means I am running the query twice. I am hoping to avoid this.
 
Set Me.RecordSet = yourRecordset

Recordset IS a property of the from. Just use the Me keyword.
 
Phil said:
Set Me.RecordSet = yourRecordset

Recordset IS a property of the from. Just use the Me keyword.

Me.RecordSet = blah --> "Method or data member not found"
||||||||||||

I'm using A97... thought I read somewhere that RecordSet was introduced
as a form property with A2000?

Thanks though.
 
Perhaps your are right.


Smartin said:
Me.RecordSet = blah --> "Method or data member not found"
||||||||||||

I'm using A97... thought I read somewhere that RecordSet was introduced as
a form property with A2000?

Thanks though.
 
No, what you want to do is:

Me.RecordSource = your_SQL_statement, e.g., "SELECT * FROM table_name WHERE
your_criteria"

Use whatever criteria you used to open the Recordset. Forget creating the
Recordset yourself - Access creates one automatically when you set the
RecordSource property of the Form.
 

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

Back
Top