Set rs = rs.OpenRecordset .......

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Set rs = rs.OpenRecordset .......

Post by Pat »

Can the following be done?
rs.close
.
.
Set rs = rs.OpenRecordset("servicejobnew")

To me it doesn't make any sense.

JohnH
3StarLounger
Posts: 287
Joined: 09 Mar 2010, 23:16
Location: Canberra Australia

Re: Set rs = rs.OpenRecordset .......

Post by JohnH »

Pat wrote: Set rs = rs.OpenRecordset("servicejobnew")
You can close a recordset, then reuse the same rs variable to open a new recordset, but it should be

Code: Select all

Set rs =db.OpenRecordset
Regards

John

User avatar
HansV
Administrator
Posts: 78627
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Set rs = rs.OpenRecordset .......

Post by HansV »

Although the Recordset object does have an OpenRecordset method, I have no idea how it works. As John states, you should use the OpenRecordset method of the Database object (for DAO) or of the Connection object (for ADODB).
Best wishes,
Hans

JohnH
3StarLounger
Posts: 287
Joined: 09 Mar 2010, 23:16
Location: Canberra Australia

Re: Set rs = rs.OpenRecordset .......

Post by JohnH »

I have just looked this up in my DAO book.

It seems that: (I think)

If you use rs.OpenRecordset you are opening a second recordset, so you should use
Set rsB = rs.OpenRecordset.

rsB will be a subset of the records in the first recordset.
Regards

John

User avatar
HansV
Administrator
Posts: 78627
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Set rs = rs.OpenRecordset .......

Post by HansV »

Thanks, that does work. If you filter rs using rs.Filter = "...", the second recordset rsB will only contain the filtered records.

But the example that Pat mentioned wouldn't work anyway - once you close a recordset, you can't open another recordset on it.
Best wishes,
Hans

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Set rs = rs.OpenRecordset .......

Post by Pat »

Thanks gents, this database has been inherited and i found that command.
As i said it didn't appear to make sense to me as you have verified.