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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textfile Into Recordset

Status
Not open for further replies.

cabobound

Programmer
Jul 11, 2007
80
US
I am trying to import a textfile into a recordset. I have found a couple examples online but they dont work. Is there a way to import a file to a recordset? The import file is a single field in a file on the server.

Thanks in advance
K
 
Not sure what you exactlt want.
I'm guessing you have a textfile with rows and columns,
and want that in a recordset??

You can open a text file and read every row like this:
Code:
Dim TextStream
 Set TextStream = file.OpenAsTextStream(ForReading, _
                                               TristateUseDefault)
    Dim Line
    ' Read the file line by line
    Do While Not TextStream.AtEndOfStream
        Line = TextStream.readline
        ' Parse the line into "fields" eg with the split() function
'store the fields in a record set (below)
    Loop
    Set TextStream = nothing

see:



You can build a record set like this:

Code:
  Set rsFSO = Server.CreateObject("ADODB.Recordset")
  Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  
  'create a row with 3 fields
  With rsFSO.Fields
    .Append "Field1", adVarChar, 200
    .Append "Field2", adDate
    .Append "Field3", adInteger
  End With
  rsFSO.Open()

  rsFSO.AddNew
  rsFSO("Field1") = "Test"
  rsFSO("Field2") = date()
  rsFSO("Field3") = 100
  rsFSO.Update

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top