keithaul
09-23-2016, 04:04 PM
I want to run a parameter query using Access 2016 VBA and then assign the result of a certain column to a variable. Below, between the = signs is my code and after the code are my questions about an error I'm getting:
=============================
Dim MyDb As DAO.Database
Dim Myqdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim MyQueryName As String
Dim strEquipName As String
MyQueryName = "GetQtyByEquipName"
strEquipName = Me.cboEquipName.Value
Set MyDb = CurrentDb()
Set Myqdf = MyDb.QueryDefs(MyQueryName)
Myqdf.Parameters("Equipment Name") = strEquipName
Set rst = Myqdf.OpenRecordset()
If rst.EOF = False Then
MsgBox rst!Quantity
End If
rst.Close
Myqdf.Close
MyDb.Close
==============================================
I'm getting the following error on this line of code - Myqdf.Parameters("Equipment Name") = strEquipName
Runtime error 3265
Item not found in collection
I am not sure what 'item not found in collection' is referring to
Here is my query, SQL view:
SELECT Equipment.EquipName, Equipment.Quantity
FROM Equipment
WHERE (((Equipment.EquipName)=[Equipment Name:]));
Why am I getting this error? and am I accessing the value that is returned by the query correctly?
Thanks
Keith
=============================
Dim MyDb As DAO.Database
Dim Myqdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim MyQueryName As String
Dim strEquipName As String
MyQueryName = "GetQtyByEquipName"
strEquipName = Me.cboEquipName.Value
Set MyDb = CurrentDb()
Set Myqdf = MyDb.QueryDefs(MyQueryName)
Myqdf.Parameters("Equipment Name") = strEquipName
Set rst = Myqdf.OpenRecordset()
If rst.EOF = False Then
MsgBox rst!Quantity
End If
rst.Close
Myqdf.Close
MyDb.Close
==============================================
I'm getting the following error on this line of code - Myqdf.Parameters("Equipment Name") = strEquipName
Runtime error 3265
Item not found in collection
I am not sure what 'item not found in collection' is referring to
Here is my query, SQL view:
SELECT Equipment.EquipName, Equipment.Quantity
FROM Equipment
WHERE (((Equipment.EquipName)=[Equipment Name:]));
Why am I getting this error? and am I accessing the value that is returned by the query correctly?
Thanks
Keith