Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Currentdb.Openrecordset

Status
Not open for further replies.

Blorf

Programmer
Dec 30, 2003
1,608
US
Hello. Whith CurrentDB.Openrecordset, Why when using a Table, is it happy, but with a Query name, or an SQL Statement is it not happy. Further, what is the solution to make Access Happy with a query?

Thank you,
ChaZ

Ascii dumb question, get a dumb Ansi
 
In what way is it not happy? What error is occurring? What, if any, error messages are being displayed? What type of recordset are you trying to open?

More information required, please.



HTH
Lightning

 
Ahh. Sorry.

I am attempting to open a query, which is based on a single table, with filters based on an open form.

The error is "Wrong Number of Arguments"

Basicly, I have a query with results based on input on an unbound form.

My function is to open this quary, make some minor changes, and have a nice day, but alas, the error I mentioned.

I solved it by using an make table query, updating the made table, and using an update query linked to the mentioned made table.

I would like to however not have to go through these extra steps.

Thanks for the reply. I can provide the code if it would help.

ChaZ





Ascii dumb question, get a dumb Ansi
 
Access VBA treats the retrieval of records from a query differently from a table for one. If you're going to use a query as a recordset use (yourrecordsetname).movelast to retrieve all the records. Then after your opening check to see if records exist (i.e. recordsetname.count > 0) do a recordsetname.moveprevious.

As far as the "wrong number of arguments" error. Are you enclosing your queries name in double quotes? The syntax is (database).openrecordset("qryname"). Make sure there aren't any spaces between the quotation marks and the parenthesis too.

Hope this works. Unfortunately my woes are different.
 
The "Wrong Number of Arguments" error message implies that the query is expecting some criteria to tell it what records to return, but is not receiving the number of criteria it expects. When this code runs, do you have your filter form open?

Can you post the code for us to look at?

HTH
Lightning
 
I have already changed the code so it functions, but the query wasn't the problem.

For what ever reason, when I run using a table name, it is happy, but with a query, it's not.

Either way, I resolved the issue, but was wondering why a query would be a problem, even something as simple as select blah.* from Blah; makes it give the number of arguments error.

Thanks,
ChaZ

Ascii dumb question, get a dumb Ansi
 
If your query has a parameter listed as its criteria (like [Please enter employee number]) so it prompts for a value when it runs, you have to supply that value when you use that query in your VBA code:

Dim wrkqdf As QueryDef, rst As Recordset
Set wrkqdf = Currentdb.QueryDefs("qryGetEmployeeInfo")
wrkqdf.Parameters(0).Value = Me.txtEENbr
Set rst = wrkqdf.OpenRecordset()
If rst.EOF = False Then
.
.
.
Hope this helps
 
It's interesting. I had this problem, and nothing I did, including the suggestions I read hear helped. Then, for a completely different reason, I installed Office 2000 Service Packs 1 - 3, and now it works.

I do appreciate all the help.

ChaZ

"When religion and politics ride in the same cart...the whirlwind follows."
Frank Herbert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top