too few parameters - expected 1

miconian

Well-known Member
Joined
Aug 18, 2004
Messages
769
Not sure what I'm doing wrong here. According to the debugger, the problem is in the "Set rst" line.

Code:
Function AnythingThere(strCurrentSite As String)

Dim strSQL As String
Dim rst As DAO.Recordset
Dim intRecordCount As Integer

strSQL = "SELECT Analyzer.[Revenue Under Goal (Lifetime)], Analyzer.[Order Line], Analyzer.[End Date],"
strSQL = strSQL + "Analyzer.[Order ID] , Analyzer.[Billing Method] FROM Analyzer WHERE "
strSQL = strSQL + "(((Analyzer.[Revenue Under Goal (Lifetime)])>0)"
strSQL = strSQL + "AND ((Analyzer.[End Date])<=(Date())+7) AND ((Analyzer.[Billing Method])='Delivery')"
strSQL = strSQL + "AND ((Analyzer.[Internet Site])=" & strCurrentSite & "))"

Debug.Print strSQL
' Run a query to see whether it comes back with anything. If not, then no need to make a corresponding table for that site.

Set rst = CurrentDb.CreateQueryDef("", strSQL).OpenRecordset
intRecordCount = rst.RecordCount

AnythingThere = intRecordCount

rst.Close
Set rst = Nothing

End Function
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi Miconian,

Try this:
Code:
Function AnythingThere(strCurrentSite As String)

Dim strSQL As String
Dim rst As DAO.Recordset
Dim intRecordCount As Integer
Dim qDef As New DAO.QueryDef

strSQL = "SELECT Analyzer.[Revenue Under Goal (Lifetime)], Analyzer.[Order Line], Analyzer.[End Date],"
strSQL = strSQL + "Analyzer.[Order ID] , Analyzer.[Billing Method] FROM Analyzer WHERE "
strSQL = strSQL + "(((Analyzer.[Revenue Under Goal (Lifetime)])>0)"
strSQL = strSQL + "AND ((Analyzer.[End Date])<=(Date())+7) AND ((Analyzer.[Billing Method])='Delivery')"
strSQL = strSQL + "AND ((Analyzer.[Internet Site])=" & strCurrentSite & "))"

Debug.Print strSQL
' Run a query to see whether it comes back with anything. If not, then no need to make a corresponding table for that site.

Set qDef = CurrentDb.CreateQueryDef("", strSQL)
Set rst = qDef.OpenRecordset
intRecordCount = rst.RecordCount

AnythingThere = intRecordCount

rst.Close
Set rst = Nothing

End Function
 
Upvote 0
dsaffo: Thanks, but I tried that, and it did not solve the problem. I am still getting the same error on the same line.
 
Upvote 0
Hi, if you paste the SQL from the debug.print into the query designer, does this return any records? Or do you recieve the same message?

BTW: you don't have to create a temp querydef to open the recordset, just write CurrentDb.OpenRecordset(sSQL)
 
Upvote 0
Looking at the SQL, what's wrong for sure is that you're missing some spaces

Code:
strSQL = "SELECT Analyzer.[Revenue Under Goal (Lifetime)], Analyzer.[Order Line], Analyzer.[End Date],"
strSQL = strSQL + "Analyzer.[Order ID] , Analyzer.[Billing Method] FROM Analyzer WHERE "
strSQL = strSQL + "(((Analyzer.[Revenue Under Goal (Lifetime)])>0)[COLOR=#ff0000][B]{SPACE}[/B][/COLOR]"
strSQL = strSQL + "AND ((Analyzer.[End Date])<=(Date())+7) AND ((Analyzer.[Billing Method])='Delivery')[COLOR=#ff0000][B]{SPACE}[/B][/COLOR]"
strSQL = strSQL + "AND ((Analyzer.[Internet Site])='" & strCurrentSite & "'))"

And arround strCurrentSite change to ])='" & strCurrentSite & "'))", thus add the single quotes as it is a string value
 
Last edited:
Upvote 0
Thanks, guys. The spaces did seem to be the issue. I have other issues with the code, but I am going to continue that conversation on the other thread.
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,306
Members
449,095
Latest member
Chestertim

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top