Solved

Access Runtime 3265 - Item not found in this collection

Posted on 2009-04-01
6
1,021 Views
Last Modified: 2013-11-27
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
Comment
Question by:keschuster
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:fabriciofonseca
ID: 24041234
Try to change

Dim qdf As DAO.QueryDef
Dim db As Database

by


Dim qdf
Dim db


Regards
0
 
LVL 28

Accepted Solution

by:
TextReport earned 500 total points
ID: 24041394
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
 

Author Comment

by:keschuster
ID: 24041606
fabriciofonseca - no go - same error

TextReport - tbl is the name of an actual table.  I copied and pasted the name.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 28

Expert Comment

by:TextReport
ID: 24041627
Then it needs to be in quotes

Set qdf = db.QueryDefs("tbl")

or you need to run it as

?getRows("tbl")

Cheers, Andrew
0
 

Author Closing Comment

by:keschuster
ID: 31565408
I was passing a TABLE name instead of a query...  DOH
0
 
LVL 28

Expert Comment

by:TextReport
ID: 24041832
"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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now