Filter recordset

brt

New member
Local time
Today, 08:37
Joined
Feb 1, 2013
Messages
7
Hi,

I want to filter records of a recordset to export them afterwards. What I did is opening a new recordset, applying the filter and then creating a new filtered recordset. While executing the code, I get an error for the following line. The error is saying that the function should at least have two arguments. Is there anyone who knows the solution?

Code:
    Dim db As DAO.Database
    Dim rst, rsf As DAO.Recordset

    Set rst = db.OpenRecordset("SELECT Archive.num_article, Archive.Division, FROM")
    rst.Filter = Form.Filter
    Set rsf = rst.OpenRecordset
 
Set rst = db.OpenRecordset("SELECT Archive.num_article, Archive.Division, FROM")

You have to have a valid query for your openrecordset command. The following has two issues:

1. the comma before the FROM clause
2. no table or query is specified in the FROM clause (I assume it should be Archive)

"SELECT Archive.num_article, Archive.Division, FROM ?

BTW, you can filter the recordset directly by using a WHERE clause in the query

"SELECT Archive.num_article, Archive.Division FROM Archive WHERE condition....."
 
Thanks. Actually, the error is in the last line:

Code:
Set rsf = rst.OpenRecordset

VBA needs to have two arguments for the OpenRecordset command. I tried to put the same two arguments, but I still get an error message.
 
You need to set db as the currentdb and I was basically trying to say to filter the initial recordset so you do not need the second at all:

Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db as CurrentDB

Set rst = db.OpenRecordset(""SELECT Archive.num_article, Archive.Division FROM Archive WHERE condition....." )

The above statement opens the filtered recordset. There is no need for the last two lines
 

Users who are viewing this thread

Back
Top Bottom