Opening a recordset from the current db

G

Guest

I get an invalid argument error when I try to open a recordset from the
current database table named dbo_CardHolder using this code:

Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("dbo_CardHolder", dbOpenTable)

Any ideas why this is invalid?
 
R

Rick Brandt

Don W said:
I get an invalid argument error when I try to open a recordset from the
current database table named dbo_CardHolder using this code:

Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("dbo_CardHolder", dbOpenTable)

Any ideas why this is invalid?

Tables named dbo_something are usually links to SQL Server tables and I'm pretty
sure you cannot open a Recordset on a link of type dbOpenTable. Try
dbOpenDynaset instead.
 
G

Guest

Yes, I did try opening the recordset using dbOpenDynaset with the same result
(invalid argument).
 
R

Rick Brandt

Don W said:
Yes, I did try opening the recordset using dbOpenDynaset with the same result
(invalid argument).

If you have references to both ADO and DAO you might need...

Dim rs As DAO.Recordset
 
G

Guest

Rick, thank you for your response!

I still don't know what was happening. Tried the module on my home PC and
it worked. I'm in the office now, and this is the line I used to get this
thing working at the office:
Set rs = CurrentDb.OpenRecordset("SELECT * FROM CardHolder")
(note that the table name was changed from dbo_CardHolder to just
CardHolder, but the table name change had no effect on the issue.)

Here at the office I never could open the recordset using the table name.
Oh well... it works using SQL.
 
J

jmorriz

You may try

Dim ds as dao.database
dim rs as dao.recordset

set ds = currentdb
set rs = ds.openrecordset("tablename", dbopendynaset)


Jim
 

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