Hi,
I've managed to get myself confused (not hard to do). I am trying to create a SQL query with criteria taken from the current record in another recordset and open it. I get the error "Run time error '3061' Too few parameters. Expected 2." This occurs on the line
Set rst3 = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
Here's the function
Public Function RemoveOnhandIng()
Dim dbs As Database
Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim rst3 As DAO.Recordset
Dim strSQL As String
Set dbs = CurrentDb
Set rst1 = dbs.OpenRecordset("SortedShoppingList", dbOpenDynaset)
Set rst2 = dbs.OpenRecordset("Pantry Contents", dbOpenDynaset)
With rst1
.MoveFirst
.Edit
End With
Dim listQuantity As String
Dim pantryQuantity As String
Dim mySearch As String
mySearch = "[Ingredient Num]=" & rst1![Ingredient Num]
Do While Not rst1.EOF
listQuantity = rst1!Quantity
If DLookup("[Ingredient Num]", "[Pantry Contents]", "[Ingredient Num] =" & rst1![Ingredient Num]) Then
'pantryQuantity = DLookup("[Quantity]", "[Pantry Contents]", "[Ingredient Num] =" & rst1![Ingredient Num])
With rst2
.FindNext mySearch
.Edit
End With
pantryQuantity = rst2!Quantity
strSQL = "SELECT ConversionFactor FROM MeasurementConversions WHERE FromUnit = '" & rst1![Unit Num] & "' AND ToUnit = '" & rst2![Unit Num] & "'"
Set rst3 = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
If Not (rst3.EOF) Then
rst3.MoveLast
End If
If rst3.RecordCount <> 0 Then
If (rst1![Unit Num] <> rst2![Unit Num]) Then
listQuantity = ConvertUnits(rst1![Unit Num], rst2![Unit Num], rst1!Quantity)
End If
End If
End Function
I've managed to get myself confused (not hard to do). I am trying to create a SQL query with criteria taken from the current record in another recordset and open it. I get the error "Run time error '3061' Too few parameters. Expected 2." This occurs on the line
Set rst3 = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
Here's the function
Public Function RemoveOnhandIng()
Dim dbs As Database
Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim rst3 As DAO.Recordset
Dim strSQL As String
Set dbs = CurrentDb
Set rst1 = dbs.OpenRecordset("SortedShoppingList", dbOpenDynaset)
Set rst2 = dbs.OpenRecordset("Pantry Contents", dbOpenDynaset)
With rst1
.MoveFirst
.Edit
End With
Dim listQuantity As String
Dim pantryQuantity As String
Dim mySearch As String
mySearch = "[Ingredient Num]=" & rst1![Ingredient Num]
Do While Not rst1.EOF
listQuantity = rst1!Quantity
If DLookup("[Ingredient Num]", "[Pantry Contents]", "[Ingredient Num] =" & rst1![Ingredient Num]) Then
'pantryQuantity = DLookup("[Quantity]", "[Pantry Contents]", "[Ingredient Num] =" & rst1![Ingredient Num])
With rst2
.FindNext mySearch
.Edit
End With
pantryQuantity = rst2!Quantity
strSQL = "SELECT ConversionFactor FROM MeasurementConversions WHERE FromUnit = '" & rst1![Unit Num] & "' AND ToUnit = '" & rst2![Unit Num] & "'"
Set rst3 = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
If Not (rst3.EOF) Then
rst3.MoveLast
End If
If rst3.RecordCount <> 0 Then
If (rst1![Unit Num] <> rst2![Unit Num]) Then
listQuantity = ConvertUnits(rst1![Unit Num], rst2![Unit Num], rst1!Quantity)
End If
End If
End Function