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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error on Query-based Report run by macro! 1

Status
Not open for further replies.

Ally72

Programmer
Nov 12, 2001
31
GB
I have a report that when opened by a command button code works fine, but when I try using a macro to run it the following error message appears:

Run-time error ‘3061’. Too few parameters. Expected 1.

The reason I wish to use a macro is I wanted to display a message box that said “No Records to View” if the report would not display anything. I use the same macro ‘code’ in other instances and there’s not a problem.

The macro uses the following function in a separate module. (The line Set r = db.OpenRecord … is highlighted when I debug the error message).

Function getCount(strRs As String)

Dim r As Recordset
Dim db As Database

Set db = CurrentDb
Set r = db.OpenRecordset(strRs)

getCount = r.RecordCount

r.Close

End Function

I can supply more info about the macro if necessary – it was just difficult to know how to lay it all out! Hope this all makes sense!
 
For the error message, I recommend that you check the sql syntax of the string strRs first.
Also, I always feel that the recordcount property of recordset is kind of tricky. Sometimes you have to go through all records to get a correct count. Why donot you use the NoData event of the report?

Seaport
 
Thank you for responding.

I hadn't actually realized that there was a NoData event on the report!

Have been checking with some others in the office and have come up with some more code which finally works.

Thank you.

Ally
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top