Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Text Data wrong record count 2

Status
Not open for further replies.

patriciaxxx

Programmer
Jan 30, 2012
277
GB
The following Microsoft example says the record count returned is 2 but I get 3. It seems to count the headings in the text file as a row of data.

What am I doing wrong?

The text file is as Microsoft states:

FirstName LastName HireDate
Nancy Davolio 16-12-12
Robert King 16-12-12

The code is Microsoft states:

Code:
[COLOR=#204A87]Function TestSchema()
Dim db As Database, rs As Recordset
Set db = OpenDatabase("c:\my documents", False, _
  False, "Text;DATABASE=c:\my documents;TABLE=contacts.txt")
Set rs = db.OpenRecordset("contacts.txt")

rs.MoveLast
Debug.Print "Record count= " & rs.RecordCount
rs.Close
End Function
[/color]
 
The fact that this function is called TestSchema suggests that it is an example of using a schema.ini file - but you have not shown the contents of that file to us. However, I don't believe the schema.ini is the cause of the problem; the cause is that the Microsoft code is wrong.

Try replacing

Set rs = db.OpenRecordset("contacts.txt")

with

Set rs = db.OpenRecordset("Select * FROM contacts.txt")

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top