RecordSets...Help!!!

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

I am trying to create a record set in Access using a query
that already exists-
Dim Rcdst As RecordSet

Set RcdSt= CurrentDb.OpenRecordSet([Query Name]) I
thought ...but no! Any help most appreciated.
Peter.
 
Peter said:
I am trying to create a record set in Access using a query
that already exists-
Dim Rcdst As RecordSet

Set RcdSt= CurrentDb.OpenRecordSet([Query Name]) I
thought ...but no! Any help most appreciated.
Peter.

You don't say what error you're getting. I can see two possible
problems:

1. You must have a reference set to the DAO Object Library. If you
also have a reference to the ADO Library, you must clarify what type of
recordset you want in the declaration:

Dim Rcdst As DAO.Recordset

2. The name of the query must be in quotes; e.g.,

Set RcdSt = CurrentDb.OpenRecordset("Query Name")

If neither of these suggestions solves your problem, please post the
exact code and the error message text and number.
 
Set RcdSt= CurrentDb.OpenRecordSet([Query Name]) I
thought ...but no! Any help most appreciated.

The argument to OpenRecordSet is a SQL String, not the name of a query
in brackets.

Try:

Dim db As DAO.Database
Dim qd As DAO.Querydef
Dim rs As DAO.Recordset
Set db = CurrentDb
Set qd = db.Querydefs("Query Name")
Set rs = qd.OpenRecordset
<do something with the recordset>
Set rs = Nothing
Set qd = Nothing
Set db = Nothing
 
John Vinson said:
Set RcdSt= CurrentDb.OpenRecordSet([Query Name]) I
thought ...but no! Any help most appreciated.

The argument to OpenRecordSet is a SQL String, not the name of a query
in brackets.

I don't follow you, John. The argument to OpenRecordset may be the name
of a query or table, though it has to be in quotes, not brackets.
 
John Vinson said:
Set RcdSt= CurrentDb.OpenRecordSet([Query Name]) I
thought ...but no! Any help most appreciated.

The argument to OpenRecordSet is a SQL String, not the name of a query
in brackets.

I don't follow you, John. The argument to OpenRecordset may be the name
of a query or table, though it has to be in quotes, not brackets.

I don't follow me either... sorry, Peter, that was indeed
incomprehensible as well as incorrect!

Resolution: don't post answers when I'm that tired.
 
Back
Top