Hi There,
I am trying to open a txt file with no header using vb6. my problem is that it's converting the first record as header. how can I solve this problem so that my first record will stay. Below is my code:

Private Sub ccommand1_Click()
Dim cnn As New ADODB.Connection, rs As New ADODB.Recordset
cnn.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\temp, "", """
rs.Open "select * from file1.txt", cnn, adOpenStatic, adLockBatchOptimistic
rs.MoveFirst
MsgBox rs.Fields(0) '2nd record
rs.MoveNext
MsgBox rs.Fields(0) '3rd record
rs.close: cnn.close
End Sub

thanks in advance.

newvbguy

Recommended Answers

All 4 Replies

if you dont have a header use this method.

Dim cnn As New ADODB.Connection, rs As New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp;Extended Properties='text;HDR=NO;FMT=Delimited'"
rs.Open "select * from file1.txt", cnn, adOpenStatic, adLockBatchOptimistic
rs.MoveFirst
MsgBox rs.Fields(0) '2nd record
rs.MoveNext
MsgBox rs.Fields(0) '3rd record
rs.Close: cnn.Close

Hi There,
I am trying to open a txt file with no header using vb6. my problem is that it's converting the first record as header. how can I solve this problem so that my first record will stay. Below is my code:

Private Sub ccommand1_Click()
Dim cnn As New ADODB.Connection, rs As New ADODB.Recordset
cnn.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\temp, "", """
rs.Open "select * from file1.txt", cnn, adOpenStatic, adLockBatchOptimistic
rs.MoveFirst
MsgBox rs.Fields(0) '2nd record
rs.MoveNext
MsgBox rs.Fields(0) '3rd record
rs.close: cnn.close
End Sub

thanks in advance.

newvbguy

Why so complicated? Just open it using text-file functions:

open "file1.txt" for input as #1

Look up examples in the help system

Here you can do like Open the text files and start reading the records :
Here is the code to work with, its 100% correct......Please check the reply back with the blog...

filename1 = "c:\mail file.txt"
Dim Data As String * 108
Dim recno As Long
    recno = 1
Close #1
    Open filename1 For Random As #1 Len = 110

Do While Not EOF(1)
        Get #1, recno, Data
        recno = recno + 1
Loop
Close #1

1. You are 4 years too late
2. You did not used code tags, that means you didn't read forum rules
3. Thread closed before another time traveller arrives..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.