In [tbl NON MAIL LIST] I have a list of all units that do not have access to e-mail. I want to cycle thru that list, taking each IDNo and using it as a paramater in the query [sqry- NON MAIL LIST]. The query extracts data from the main table [tbl DATA]. Then I want to print the report [rpt NON MAIL]. The Record Source of the form is [sqry- NON MAIL LIST].
Below is my code. When I run the procedure, I get the error message "Run-time error 3265. Item not found in this collection". Can anyone tell me what I'm doing wrong? Thanks.
Dim IDNoFile As String
Dim NoRecords As Long
Dim I As Long
Dim dbs As Database
Dim rstList As Recordset
Dim fldFinNoFile As Field
Dim qryList As QueryDef
Set dbs = CurrentDb
Set rstList = dbs.OpenRecordset("tbl NON MAIL LIST"
Set fldIDNoFile = rstList.Fields("FILE NAME"
Set qryList = dbs.QueryDefs("sqry- NON MAIL LIST"
NoRecords = rstList.RecordCount
For I = 1 To NoRecords
IDNoFile = Left(fldIDNoFile.Value, 6)
qryList.Parameters![FINANCE] = IDNoFile
DoCmd.OpenReport "rpt NON MAIL"
rstList.MoveNext
Next I
Exit Function
Below is my code. When I run the procedure, I get the error message "Run-time error 3265. Item not found in this collection". Can anyone tell me what I'm doing wrong? Thanks.
Dim IDNoFile As String
Dim NoRecords As Long
Dim I As Long
Dim dbs As Database
Dim rstList As Recordset
Dim fldFinNoFile As Field
Dim qryList As QueryDef
Set dbs = CurrentDb
Set rstList = dbs.OpenRecordset("tbl NON MAIL LIST"
Set fldIDNoFile = rstList.Fields("FILE NAME"
Set qryList = dbs.QueryDefs("sqry- NON MAIL LIST"
NoRecords = rstList.RecordCount
For I = 1 To NoRecords
IDNoFile = Left(fldIDNoFile.Value, 6)
qryList.Parameters![FINANCE] = IDNoFile
DoCmd.OpenReport "rpt NON MAIL"
rstList.MoveNext
Next I
Exit Function