473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

3265 - Item Not Found In This Collection

I keep getting this error and it's driving me crazy:
3265 - Item Not Found In This Collection
I'm using MS Access 2003. Through VBA I'm attempting to fill in an excel spreadsheet with a query based on a table. Here is my code (setting the QueryDef is causing the error, see text in bold/italics):
Expand|Select|Wrap|Line Numbers
  1.     Dim MyExcel As Excel.Application
  2.     Dim MyWorkbook As Excel.Workbook
  3.     Dim MyWorksheet As Excel.Worksheet
  4.     Dim strMyWorkbook As String
  5.     Dim strSQL As String
  6.     Dim dbs As Database
  7.     Dim qdf As QueryDef
  8.     Dim rst As Recordset
  9.  
  10.     ' Open the MonthlyBreakdown spreadsheet
  11.     strMyWorkbook = GetPathOrName(GetDatabasePathAndName()) & "\Copy of MonthlyBreakdown.xls"
  12.     Set MyExcel = New Excel.Application
  13.     Set MyWorkbook = MyExcel.Workbooks.Open(strMyWorkbook)
  14.     Set dbs = CurrentDb()
  15.  
  16.     strSQL = "SELECT DISTINCTROW Left([tblTransaction].[Treaty],6) AS Treaty6, " & _
  17.              "Sum(tblTransaction.txnPremium1) AS BasePrem, " & _
  18.              "Sum(tblTransaction.txnAllowance1) AS BaseAllow, " & _
  19.              "Sum(tblTransaction.txnPremium2) AS ADBPrem, " & _
  20.              "Sum(tblTransaction.txnAllowance2) AS ADBAllow, " & _
  21.              "Sum(tblTransaction.txnPremium3) AS WaiverPrem, " & _
  22.              "Sum(tblTransaction.txnAllowance3) AS WaiverAllow, " & _
  23.              "Sum(tblTransaction.txnPremium4) AS XtraPrem, " & _
  24.              "Sum(tblTransaction.txnAllowance4) AS XtraAllow " & _
  25.              "FROM tblTransaction " & _
  26.              "WHERE (((Left([tblTransaction].[txnBillingDate], 6)) = [Forms]![frmDates]![cmbYear] & [Forms]![frmDates]![cmbMonth])) " & _
  27.              "GROUP BY Left([tblTransaction].[Treaty],6) " & _
  28.              "ORDER BY Left([tblTransaction].[Treaty],6), Sum(tblTransaction.txnPremium1)"
  29.  
  30.     Set qdf = dbs.QueryDefs(strSQL)
  31.     qdf("[Forms]![frmDates]![cmbYear]") = [Forms]![frmDates]![cmbYear]
  32.     qdf("[Forms]![frmDates]![cmbMonth]") = [Forms]![frmDates]![cmbMonth]
  33.     Set rst = qdf.OpenRecordset()
  34.  
Please note that when instead of putting the SQL into VBA, if I use an existing query, the code then works. I've taken the SQL straight from this query and pasted it into VBA, so I don't see any reason why it wouldn't work. I've written similar code to this before and had no problems.

Any help you can give me would be appreciated. Thanks.
Mar 13 '07 #1
4 6454
MMcCarthy
14,534 Expert Mod 8TB
You need ...

Expand|Select|Wrap|Line Numbers
  1. Set qbf = dbs.CreateQueryDef(strSQL)
as you are creating a new query definition.

Mary
Mar 13 '07 #2
Okay. I replaced:
Set qdf = dbs.QueryDefs(strSQL)
with:
Set qdf = dbs.CreateQueryDef(strSQL)

I'm no longer getting error 3265 (Items Not Found).
I'm now getting error 3125 - followed by my SQL statement.
Am I using this method incorrectly?
Mar 13 '07 #3
It looks like it was requiring me to name the querydef:
Set qdf = dbs.CreateQueryDef("",strSQL)

That part of my codes seems to be working now.

Thanks mmcarthy!!!!
Mar 13 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
It looks like it was requiring me to name the querydef:
Set qdf = dbs.CreateQueryDef("",strSQL)

That part of my codes seems to be working now.

Thanks mmcarthy!!!!
You're welcome.
Mar 13 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Lee Stafford via AccessMonster.com | last post by:
I get this error message when I type in a new value. The code behind this combo box is: Private Sub City_NotInList(NewData As String, Response As Integer) Response = Append2Table(Me!,...
0
by: rajkalacbe | last post by:
I am running a visual basic executable program through Forms4.5 of D2K using Forms menu options.. When I Invoke this form in the server where I have the database installed, I do not have any...
6
by: darkhat01 | last post by:
I am getting a Run-Time error '3265': Item cannot be found in the collection corresponding to the requested name or ordinal. The Function call I am using is: ...
1
by: wassimdaccache | last post by:
Hello Please help me I working on database using access 2003 I'm writing into a save bottom on a form this code to insert some of my value on another table ...no relationship between them ...
2
by: marcohod | last post by:
Hi, I'm using ADO 2.8 in VB6 to use an SQL Server 2000 database. This works: Dim MyRS2 As New ADODB.Recordset MySQL = "Select * from table1" MyRS2.Open MySQL, sqlConnection,...
3
by: DGNinja12 | last post by:
I get this error when i run, i cant figure out what is wrong Can some one please help me? Run-time error '3265': Item cannot be found in the collection corresponding to the requested name or...
16
by: zandiT | last post by:
hello i'm using the microsoft audit trail example ACC2000: How to Create an Audit Trail of Record Changes in a Form and im having a problem with my recordset. in the example they are using a...
0
nurikoAnna
by: nurikoAnna | last post by:
Dim rsFaculty As New ADODB.Recordset Dim rsDepartment As New ADODB.Recordset Dim oCm As New ADODB.Command Private Sub Disconnect() connect.Close End Sub
8
by: charli | last post by:
Error 3265, "Item cannot be found in the collection corresponding to the requested name or ordinal" code programatically opens a query using ADOX and changed the sql Dim cat As New...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.