Items not in collection error

Q

quixote

I am getting a runtime error 3265 on the following code.
When I run this and mouse over the line where the error
breaks on, it shows me the info from the last record in my
table. When I mouse over the following area:
......rs.Fields(i).....
I get an "Item not found in this collection" error.

Any ideas on what I have scripted improperly?
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim textline
Dim i As Integer

Set db = CurrentDb
Set rs = db.OpenRecordset("tblMonthlyFTP")

HeaderText = "TestStuff"

Open "Y:\Quality\filename.csv" For Output As #1

'print the header
Print #1, HeaderText



Do While Not rs.EOF()

'create the tilde delimited line

For i = 1 To rs.Fields.Count

ERROR HERE>>>>> textline = textline & rs.Fields(i) & "~"
Next
'get rid of last tilde
textline = Left(textline, Len(textline) - 1)
'print the line and move down to next line
Print #1, textline; vbCrLf
Loop

Close #1
 
S

Sandra Daigle

Try looping from 0 to rs.fields.count - 1 - the members of a collection
begin with 0.
 
M

Marshall Barton

quixote said:
I am getting a runtime error 3265 on the following code.
When I run this and mouse over the line where the error
breaks on, it shows me the info from the last record in my
table. When I mouse over the following area:
.....rs.Fields(i).....
I get an "Item not found in this collection" error. [snip]

For i = 1 To rs.Fields.Count

ERROR HERE>>>>> textline = textline & rs.Fields(i) & "~"


Collection indexes start at zero.

For i = 0 To rs.Fields.Count - 1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top