Item not found in collection error

ritco

Registered User.
Local time
Today, 14:24
Joined
Apr 20, 2012
Messages
34
I am trying to establish a recordset in which I can pull information from a query to populate text boxes on a form. I want the query results to be based on two fields on the form (item & warehouse).
My original code was giving me the “too few parameters. expected 2” error. I had the parameters in the query itself.
I found a post on this site with instructions and a link to http://support.microsoft.com/default...b;en-us;209203 in which suggested the code below. The error I’m getting with this code is “Item not found in collection.”
Can anyone tell me what I’m doing wrong?

Dim db As Database
Dim rsTable As Recordset
Dim qdfPara1 As QueryDef
Dim strSearchItem As String
Set db = CurrentDb
Set qdfPara1 = db.QueryDefs("QryGetItemInfo")

‘When I hover this line, I see the correct item number
strSearchItem = Forms![frmInvValItemMaint]![txtItem]

‘This is the error line in debug
qdfPara1![Forms!frmInvValItemMaint!txtItem] = strSearchItem

Set rsTable = qdfPara1.OpenRecordset()

Me.TxtDescription.Value = rsTable![Description]

p.s. I took out the extra line references to the warehouse to simplify things
 
Try...
Code:
qdfPara1(Forms!frmInvValItemMaint!txtItem) = strSearchItem
 
That did not work either...same message. :(
 
I think I figured out where I messed up. My code is right but I had removed the [Forms]![frmInvValItemMaint]![txtStkCode] criteria reference from my query.
Once I added that back in, all seems to work now.
Thanks!
 

Users who are viewing this thread

Back
Top Bottom