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?
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?
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.
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.