• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1044
  • Last Modified:

Access Runtime 3265 - Item not found in this collection

I have this code in a database that works just fine.  I moved it into a new database I'm working on and it throws this error.

The only difference I can see is in the references with Microsoft DAO 3.6 Object Library.  The database that works has this checked.  The one that throws the error does not.

I tried to enable this in the new DB and I get the error:
"Name Conflicts with existing module, project, or library.

It's not already selected in the preferences window.  How do I track this down?


Public Function getRows(tbl As String)
Dim qdf As DAO.QueryDef
Dim db As Database
Set db = CurrentDb()
Set qdf = db.QueryDefs(tbl)                          >>>>>>>>  Error's Here
r = qdf.OpenRecordset.RecordCount
'MsgBox r
Set rs = Nothing
Set db = Nothing
getRows = r
End Function

Open in new window

0
keschuster
Asked:
keschuster
  • 3
  • 2
1 Solution
 
fabriciofonsecaCommented:
Try to change

Dim qdf As DAO.QueryDef
Dim db As Database

by


Dim qdf
Dim db


Regards
0
 
TextReportCommented:
I suspect the value you are passing as your parameter to the getRows function, tbl, is not a valid QueryDef name in your current database.
Cheers, Andrew
0
 
keschusterAuthor Commented:
fabriciofonseca - no go - same error

TextReport - tbl is the name of an actual table.  I copied and pasted the name.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
TextReportCommented:
Then it needs to be in quotes

Set qdf = db.QueryDefs("tbl")

or you need to run it as

?getRows("tbl")

Cheers, Andrew
0
 
keschusterAuthor Commented:
I was passing a TABLE name instead of a query...  DOH
0
 
TextReportCommented:
"I was passing a TABLE name instead of a query... DOH"
The code below will do the same job but will work for a TableName, QueryName or valid SELECT Statement.
Cheers, Andrew
Public Function getRows(tbl As String)
Dim db As DAO.Database
Dim rst as DAO.Recordset
    Set db = CurrentDb()
    Set rst = db.OpenRecordset("SELECT COUNT(*) AS Qty FROM (" & tbl & ")")
    r = rst!Qty
    Set rs = Nothing
    Set db = Nothing
    getRows = r
End Function

Open in new window

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now