Runtime error 3061 Too few parameters (1 Viewer)

banza

Registered User.
Local time
Today, 11:08
Joined
Jul 2, 2005
Messages
11
Hello Access friends,
What is wrong with the following code (modified the module from http://members.iinet.net.au/~allenbrowne/AppInventory.html ):
I Keep getting a runtime error 3061 Too few parameters . Expected 1 on the line highlight below.
I have the reference MS DAO 3.6 selected and I am using access 2000 and calling the module from a command button in a form.
Thanks in advance for taking the time to help me out.

Dim db As DAO.Database 'CurrentDb()
Dim rs As DAO.Recordset 'Various recordsets.
Dim strProduct As String 'vProductID as a string.
Dim strAsOf As String 'vAsOfDate as a string.
Dim strSTDateLast As String 'Last Stock Take Date as a string.
Dim strDateClause As String 'Date clause to use in SQL statement.
Dim strSQL As String 'SQL statement.
Dim lngQtyLast As Long 'Quantity at last transaction.
Dim lngQtyAcq As Long 'Quantity acquired since incoming transaction.
Dim lngQtyUsed As Long 'Quantity used since outgoing transaction.

If Not IsNull(vProductID) Then
'Initialize: Validate and convert parameters.
Set db = CurrentDb()
strProduct = vProductID
If IsDate(vAsOfDate) Then
strAsOf = "#" & Format$(vAsOfDate, "mm\/dd\/yyyy") & "#"
End If

'Get the last transaction date and quantity for this product.
If Len(strAsOf) > 0 Then
strDateClause = " AND ([TransacDate] <= " & strAsOf & ")"
End If
strSQL = "SELECT TOP 1 [TransacDate], [Quantity] FROM [Transactions] " & _
"WHERE ((ProductID = " & strProduct & ")" & strDateClause & _
") ORDER BY TransacDate DESC;"

Set rs = db.OpenRecordset(strSQL)
With rs
If .RecordCount > 0 Then
strSTDateLast = "#" & Format$(![TransacDate], "mm\/dd\/yyyy") & "#"
lngQtyLast = Nz(!Quantity, 0)
End If
End With
rs.Close

'Build the Date clause
If Len(strSTDateLast) > 0 Then
If Len(strAsOf) > 0 Then
strDateClause = " Between " & strSTDateLast & " And " & strAsOf
Else
strDateClause = " >= " & strSTDateLast
End If
Else
If Len(strAsOf) > 0 Then
strDateClause = " <= " & strAsOf
Else
strDateClause = vbNullString
End If
End If

'Get the quantity acquired since then.
strSQL = "SELECT Sum([Transactions].[Quantity]) AS QuantityAcq " & _
"FROM [Transactions]" & _
"WHERE (([Transactions].[ProductID] = " & strProduct & ") AND ([Transactions].[TransacType] = 'Incoming')"
If Len(strDateClause) = 0 Then
strSQL = strSQL & ");"
Else
strSQL = strSQL & " AND ([Transactions].[TransacDate] " & strDateClause & "));"
End If

Set rs = db.OpenRecordset(strSQL)
If rs.RecordCount > 0 Then
lngQtyAcq = Nz(rs!QuantityAcq, 0)
End If
rs.Close

'Get the quantity used since then.
strSQL = "SELECT Sum([Transactions].[Quantity]) AS QuantityUsed " & _
"FROM [Transactions]" & _
"WHERE (([Transactions].[ProductID] = " & strProduct & ") AND ([Transactions].[TransacType] = 'Outgoing')"
If Len(strDateClause) = 0 Then
strSQL = strSQL & ");"
Else
strSQL = strSQL & " AND ([Transactions].[TransacDate] " & strDateClause & "));"
End If

Set rs = db.OpenRecordset(strSQL)
If rs.RecordCount > 0 Then
lngQtyUsed = Nz(rs!QuantityUsed, 0)
End If
rs.Close

'Assign the return value
OnHand = lngQtyLast + lngQtyAcq - lngQtyUsed
End If

Set rs = Nothing
Set db = Nothing
Exit Function
End Function
 

WayneRyan

AWF VIP
Local time
Today, 04:08
Joined
Nov 19, 2002
Messages
7,122
Banza,

Single-Quotes ...

"WHERE ((ProductID = '" & strProduct & "')" & strDateClause

Wayne
 

banza

Registered User.
Local time
Today, 11:08
Joined
Jul 2, 2005
Messages
11
Runtime error

Hi Wayne,
you have saved my day. It works.....thank you very much!

May God bless you.
 

WayneRyan

AWF VIP
Local time
Today, 04:08
Joined
Nov 19, 2002
Messages
7,122
Banza,

No problem, you were doing so well with the "#"s and such.

Wayne
 

Users who are viewing this thread

Top Bottom