0

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

Edited by peter_budo: Adding code tags to old post

5
Contributors
4
Replies
6
Views
10 Years
Discussion Span
Last Post by peter_budo
0

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
0

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

0

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

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

0

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..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.