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!

Write to TextFile

Status
Not open for further replies.

ravula2000

IS-IT--Management
Mar 8, 2002
205
US
I have a table where Id and notes fields is stored.
I want to take few records and want to create a text file with the name of the Id.
I want to do this using MSAccess forms.
Can any body please explain me who to create it.
Iam good in VB but not familiar with Ms-Access.

Please advise me..

Thanks
Srini
 
Hi TomThumbKP,
Here is the code that I can use in VB after setting refernces to Ado 2.6 library..

Private Sub CreateTextFile_Click()
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
Dim rs As ADODB.Recordset
cn.Open "dsn=csis;uid=u1;pwd=p1"
Set rs = cn.Execute("select id, notes from idnotes")
rs.MoveFirst
Dim i As Integer
i = FreeFile
Open rs("id") & "" For Output As #i
Do Until rs.EOF
Print #i, rs("notes")
Loop
Close #i
rs.Close
cn.Close
End Sub

Thanks
srinivas
 
If it were me (and there are probably better ways), then I would use the Scripting.Filesystem object. A quick example:
Code:
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.CreateTextFile("c:\temp\Test.txt")
oFile.WriteLine "Hello, world!"
Set oFile = Nothing
Set oFSO = Nothing
 
Agree with TomThumb. Used it several times on large scale and it works fine. Just remember to close in the end. From my own code for a file named batches:

Your DIMS goes here

Set FileSystem1=CreateObject "Scripting.FileSystemObject")
Set MakeBatchesFile=FileSystem1.CreateTextFile("C:\My Documents\Batches.txt", True)

MakeBatchesFile.WriteLine ("Y05433")
MakeBatchesFile.WriteLine ("END")
MakeBatchesFile.Close

Let me know if you need clarification.

Jens
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top