My VB6 project has a data control with
Data1.Connect = Text;
Data1.RecordSource = MyFile#txt
Data1.Options = 0
Data1.RecordsetType = 0
MyFile.txt is a comma delimited file with two fields.
Sample records:
qweqwe,rtyrty
asdasd,fghfgh
zxczxc,"vbnvbn" <-- Note that some records can have a quote
fghfgh,jkljkl
xcvxcv,bnmbnm
If the quotes are stripped from the file before
running this code, there is no error.
We don't want to have to tell our customers that they
have to search and replace the double quotes in their
file before they use our software.
For simplicity's sake, here's an abbreviated code
snippet that illustrates how and where the error
is being generated:
On Error GoTo 0
Do While Not Data1.Recordset.EOF
Debug.Print Data1.Recordset(0)
Debug.Print Data1.Recordset(1)
Data1.Recordset.MoveNext
Loop
Run-time error '-2147417848(80010108)':
Automation error
The object invoked has disconnected from its clients.
I click on debug and the code appears with
the break highlighted at the line that says
Debug.Print Data1.Recordset(0).
I click the run button and another error immediately
appears:
Run-time error '3015':
" isn't an index to this table. Look in the indexes
collection of the TableDef to determine the valid
index names.
I click on debug and the code appears with
the break highlighted at the same line as before.
I then change the line
On Error GoTo 0
to
On Error Resume Next.
Then there is no break on the error, but the execution
stops as if the record with the double quotes is the
last record in the file. If it continued to read
records after the problem record I'd simply use
On Error Resume Next, but I can't do that because
all of the records in the file have to be read.
My question is, is there a way to do this so that
double quotes are ignored and all of the records
are read? Is there some property of the data control
that needs to be set differently?
Thanks in advance.