Re: A command button (Access) that saves the current record in a file
- From: "SurendranSNV via AccessMonster.com" <u23007@uwe>
- Date: Thu, 20 Jul 2006 08:42:38 GMT
Try this.
================= Start Code ============================
'First set a reference to "Microsoft Scripting Runtime"
'In the onclick event of command button
'try this code.
'Make changes as appropriate
Private Sub cmdInsert_Click()
Dim fso As New FileSystemObject
Dim ts As TextStream
Dim strFilePathAndName As String
strFilePathAndName = "C:\Sample.TXT"
Dim rst As DAO.Recordset
'Assuming your current data is in a subForm control
Set rst = Me.frmTextFileDemoSub.Form.RecordsetClone
'set recordset object rst to current record
rst.Bookmark = Me.frmTextFileDemoSub.Form.Bookmark
'Create a new file for writing
'If text file already exists,it will be overwritten
'otherwise a new file will be created
Set ts = fso.CreateTextFile(strFilePathAndName, True)
'Write field values in text file
ts.WriteLine rst!LotID
ts.WriteLine rst!DeviceName
ts.WriteLine rst!Qty
'Close the file.
ts.Close
'Close the recordset
Set rst = Nothing
End Sub
============================= End Code ============================
Surendran
SurendranSNV at Hotmail dot com
Arnold wrote:
The command button which would simply create a text file that would contain
some information on the current record selected. For example, the current
record selected (say record no4), contains a Lot ID (say, N12453.1), a device
Name, (AD8618ARCU-SHRT), and Qty (say 200units). I would like to save these
three entries automatically in a text file by simply clicking the command
button.
The result is after clicking the button a new file was created say it was
stored at C:\sample.txt. The sample.txt should contain:
N12453.1
AD8618ARCU-SHRT
200
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-externaldata/200607/1
.
- Prev by Date: Re: Import 'Choice' Data into Access From Excel
- Next by Date: Re: Automated Text File Import
- Previous by thread: RE: Import fails and .mdb file balloons up in size!
- Next by thread: Convert Hierarchial Report to Access Table
- Index(es):