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

Hi guys. i have a text file like

Status
Not open for further replies.

MAK9974

IS-IT--Management
Apr 11, 2002
145
US
Hi guys.

i have a text file like this (say 50000 records)
eg:
"Id = '1' name ='mak' amount = '100'"

I need to bring those in to recordset like so that i can scroll thru

rec.fields('id') =1
rec.fields('name') ='MAK'
rec.fields('amount') =100


I dont have any database or tables in access or sql or oracle.

can i create recordset in memory?

if iis possible please post me some code
-MAK
 
There is a lot you can do with ADO recordsets

In this first example, a recordset is created and a delimited text file is directly in to it. Once read in you can use all the methods available to ADO to sort through your data.


'Under Tools / references menu - Set a reference to Microsoft ADO 2.1
Private Sub Sample2()
Dim cnSample As New ADODB.Connection
Dim rsSample As New ADODB.Recordset

cnSample.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};" _
& "Dbq= C:\Development\Excel\ADO\;" _
& "Extensions=asc,csv,tab,txt;HDR=NO;" _
& "Persist Security Info=False"

rsSample.Open "Select * From Sample.txt", cnSample, 3, 3, adCmdText
Do While rsSample.EOF <> True
rsSample.MoveNext
Loop

MsgBox rsSample.RecordCount
rsSample.moveFirst
Msgbox rsSample(1)

End Sub


If your text file is actually formated exactly as you described where Id = '1' name ='mak' amount = '100' (rather than 1, mak, 100) then you will have to parse through the file and then read it into a recordset. In such case maybe you can look at using a standalone recordset.

see following post for details --> thread709-298677 it is of some help
 
That last posting did not format correctly and cut off a few words

It should have read - &quot;I hope it is of some help&quot;
 
i dont want to connect using ado to a text file.

i need to use recordset and assign values.

i need to use any kind of recordset but i dont want to connect to physical file. I want to use OPEN #1

polease send me a code that can b used without connecting to the file directly.

thanks advance

-MAK
 
I have added some code to show you different methods of reading a text file with the Open method as you requested.

Just a note however that using the Open Statement does NOT create a recordset. To create a recordset you would have to use one of the two previously mentioned methods.
A stand alone recordset ( javascript:gothread(709,298677) )resides in memory and does NOT connect to your text file, therefore you would still have to use one of the methods below to open and read in the text file into it. You can think of a stand alone recordset as a friendly / easier alternative to using / manipulating an array.



Sub Sample()
ReadFile1 &quot;C:\Development\Excel\ADO\Sample.txt&quot;
ReadFile2 &quot;C:\Development\Excel\ADO\Sample.txt&quot;
ReadFile3 &quot;C:\Development\Excel\ADO\Sample.txt&quot;
End Sub

'Read each word
Function ReadFile1(FileDir As String)
Open (FileDir) For Input As #1
Do Until EOF(1)
Input #1, strString
MsgBox strString
Loop
Close #1
End Function

'Read the entire file at once
Function ReadFile2(FileDir As String)
Open FileDir For Input As #1
MsgBox Input(LOF(1), 1)
Close #1
End Function

'read one line at a time
Function ReadFile3(FileDir As String)
Open FileDir For Input As #1
Do Until EOF(1)
Line Input #1, Data
MsgBox Data
Loop
Close #1
End Function
 
Thank you very much.

you are awesome

-MAK
 
I am working on my first programming project and i need help.
I need to open a csv file, delete the first 15 rows in it then take into a sql table in an existing database.

Note: the 16th record contains the field names that i need to use. I was using Microsoft Jet 4.0 and i couldn't edit the recordset to delete the rows i don't need.

I could really use the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top