Question : SQL String error. 'Too few parameters. Expected 1.'

This is the first question I have ever posted on this forum so I hope it's not too obvious what I'm doing wrong! :)

Public Function Get_0_inf(VarNum As Integer) As Double

Dim strSQL As String
Dim r As DAO.Recordset
Dim db As DAO.Database

   Set db = CurrentDb()

   strSQL = "SELECT Sum(qry_sel_calc_bucket_totals.INFLOWS) AS Sum_Inflow " & _
   "FROM qry_sel_calc_bucket_totals " & _
   "WHERE ((qry_sel_calc_bucket_totals.[Bucket]=666) AND (qry_sel_calc_bucket_totals.[CCY]=" & VarNum & "));"

   Set r = db.OpenRecordset(strSQL)

   If IsNull(r!Sum_Inflow) Then
       Get_0_inf = 0
   Else
       Get_0_inf = r!Sum_Inflow
   End If

   r.Close

End Function

Calling the above Function using Get_O_inf(978) in a procedure results in the error message. I assume my concatenation is wrong but I can't figure it out. Appreciate any help on offer.

Answer : SQL String error. 'Too few parameters. Expected 1.'

Solved. I decided that problem must lie in the date being used as a criteria in one of the parent queries rather than the function itself so I decided to simply create QueryDefs, hard coding the form control's value via concatenation. That seems to have done the trick. Very odd though. Think it must be down to my inefficient use of queries. Well I learn! Thanks for your help.
Random Solutions  
 
programming4us programming4us