Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime error defining parameters

Status
Not open for further replies.

theSizz

Technical User
Apr 22, 2002
93
US
The following line of code:
qdf.Parameters(0) = sYr

is producing a runtime error 3265 “Item not found in this collection”

I know I can use a form for the qdf.Parameters(0) line like this:
qdf.Parameters(0) = [Forms]![frm52Weeks]![cboYr]

But I don’t want to use a form in this particular instance, I want the parameter to come from an input box. The user enters a four digit number for the year e.g. 2008. The data type for the year field in the table is number not date.

This is a portion of the code I’m using.
Code:
Dim sYr As String
sYr = InputBox("Enter Year Please")
If sYr = "" Then
    MsgBox "You did not enter a year", , "Aborting..."
    Exit Sub
End If

Set db = CurrentDb
Set qdf = db.QueryDefs("qryWeeklySumsQK")
qdf.Parameters(0) = sYr

Set rs = qdf.OpenRecordset
Do While Not rs.EOF
    If rs!SumOfNet > 1 Then
     tmpWin = tmpWin + 1
     tmpLoss = 0
    End If
     
    If rs!SumOfNet < 1 Then
     tmpLoss = tmpLoss + 1
     tmpWin = 0
    End If
    
    If tmpLoss > ConsqLWk Then ConsqLWk = tmpLoss
    If tmpWin > ConsqWWk Then ConsqWWk = tmpWin

rs.MoveNext

Loop

Me.txtConsecWWk.Value = ConsqWWk
Me.txtConsecLWk.Value = ConsqLWk

rs.Close
qdf.Close

Can anyone help with the proper syntax?

Thanks for looking at this.
 
This may be a sophomoric answer, but last night working on a project I received the same error message. I looked for a while and found that I had a misspelled "Repalcment" in the table definition, but I spelled it correctly "Replacement" in the code. When it went looking for it in the collection, there was no such properly spelled control.

Once I corrected the spelling (or actually matched the bad spelling) things worked.

Not sure if this is of any help, but I thought I'd pass that along.

Best of luck; Pampas58
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top