473,394 Members | 1,702 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,394 software developers and data experts.

item cannot be found in collection corresponding to the requested name or ordinal

9
I am seeking help to try and fix an error that I am getting inside of my excel vba code. I am trying to import the column names of a sql table into an excel worksheet. When I run this code:

[For intCount = 0 To rsmyf.Fields.Count
Range("A2").Offset(intCount, 0).Value = rsmyf(intCount).Name]

I get this error: Run-time error '3265'- Item cannot be found in the collection corresponding to the requested name or ordinal. The error appears here - ".Name"

Can someone tell me what I need to do to fix this?
Nov 21 '11 #1
14 13819
Rabbit
12,516 Expert Mod 8TB
rsmyf(intCount) This attempts to access the value of the field at the current record.

What you're probably trying to do is access the field itself. rsmyf.Fields(intCount)
Nov 21 '11 #2
dsal3
9
I made the change to rsmyf.Fields(intCount)and now I get the following error:

Run-time error '1004': Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
Nov 21 '11 #3
dsal3
9
I changed my code back to this:

[For intCount = 0 To rsmyf.Fields.Count
Range("A2").Offset(intCount, 0).Value = rsmyf(intCount).Name]

It gave me the column names of the sql table that I am referencing in the correct location in my excel spreadsheet, but it still errors and will not continue with the rest of my code.
Nov 21 '11 #4
Rabbit
12,516 Expert Mod 8TB
What's the definition/sql of the recordset?
Nov 21 '11 #5
dsal3
9
I made some changes to the code that I originally posted. The connection to the sql db and table is defined above the code below:

[strSQL = "SET NOCOUNT ON"
strSQL = strSQL & " SELECT * FROM Testtbl where 1=2 "

Set rsmyf = New ADODB.Recordset
rsmyf.Open strSQL, connmyf, adOpenStatic, adLockOptimistic

For intCount = 0 To rsmyf.Fields.Count - 1
Range("A2").Offset(intCount, 0).Value = rsmyf.Fields(intCount)
Next]
Nov 21 '11 #6
Rabbit
12,516 Expert Mod 8TB
Your query returns no records. That's why it can't access the "current record" because there are none.
Nov 21 '11 #7
dsal3
9
Ok, how can I fix it do that it only returns the column names?
Nov 21 '11 #8
dsal3
9
sorry, how can I fix it so that the query only returns the column names in the table?
Nov 22 '11 #9
Rabbit
12,516 Expert Mod 8TB
You can either return a record, or you can query the system table.
Nov 22 '11 #10
dsal3
9
Can you tell me what the syntax should be for both?
Nov 22 '11 #11
dsal3
9
I changed my syntax to query the system table.

strSQL = "Select column_name from information_schema.columns where table_name='Testtbl'"

This returns all of the column names, however, I am still getting this error: item cannot be found in collection corresponding to the requested name or ordinal. Can someone please help me fix this error? The code is erroring out on this ' = rsmyf.Fields(intCount)'


[For intCount = 0 To rsmyf.Fields.Count
Range("A2").Offset(intCount, 0).Value = rsmyf.Fields(intCount)
Next]
Nov 22 '11 #12
Rabbit
12,516 Expert Mod 8TB
If you're querying the system table, you no longer want to return the fields of the recordset. Instead, you have to iterate through the rows of the recordset.
Nov 22 '11 #13
dsal3
9
Can you tell me how that can be done in my code?
Nov 22 '11 #14
Rabbit
12,516 Expert Mod 8TB
I don't know VB 4/5/6 so I can only give you pseudocode. You'll have to port it appropriately.
Expand|Select|Wrap|Line Numbers
  1. recordset.MoveFirst
  2. Do While Not recordset.EOF
  3.   something = recordset(1)
  4.   recordset.MoveNext
  5. Loop
Nov 22 '11 #15

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

Similar topics

4
by: nc | last post by:
My iterator can find my collection when my Action class calls my jsp directly, however when my Action class calls an html file that is set up with IFrames (one of which is loading that same jsp), I...
5
by: J. Muenchbourg | last post by:
The field name 'articleid', which is an identity/primary key , is not being recognized in my recordset as I get an " Item cannot be found in the collection corresponding to the requested name or...
2
by: CJM | last post by:
I'm running a stored procedure that inserts a record into a table then returns the Identity field value. I've done this kind of thing plenty of times in the past, but I'm obviously doing something...
2
by: RBohannon | last post by:
I had some help on this one earlier, but I'm still having a bit of trouble. I'm sure it's something simple that I just don't know. I'm using Access2000. I have one table with employee salary...
1
by: grgimpy | last post by:
This code is supposed to take the last three records entered into the query "Ni-Au-CooperSubformQuery" and place them in the table MyTable. After placing the three records in the table it should...
2
by: indhu | last post by:
Hi its not working, i want only distinct record. here its repeated records coming. accdb = "SELECT DISTINCT sequence FROM scene WHERE sceneid = '" & myquery & "' " and when i select the...
2
by: meyousikmann | last post by:
This will be difficult to explain so bear with me. If anyone is familiar with Tibco Rendezvous and/or Microsoft Messaging, this may make more sense. I've created a hierarchy of objects that...
3
by: martin | last post by:
Hello, Could someone here please explain the reason for the error in the subject (the full error below) I dont get this everytime and i've never gotten while debugging. The code (also below)...
2
by: Sticksboy | last post by:
I keep getting this error message - Item cant be found in the collection corresponding to the requested name or ordinal I dont understand what it means to be honest. I am trying to get the code...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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.