Re: A command button (Access) that saves the current record in a file

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • Re: coding help - please
    ... the DAO recordset is empty. ... DoCmd.SendObject acSendReport, "All Emp Time", acFormatSNP, ... Dim rst As DAO.Recordset ... Set rst = CurrentDb.OpenRecordset("All ...
    (microsoft.public.access.modulesdaovba)
  • Re: Exporting data from an append table into excel without field h
    ... this is the most simple code to export to excel using copy from recordset. ... Dim objXLApp As Object 'Excel.Application ... Set rst = CurrentDb.OpenRecordset ... Set objXLWs = objXLWb.Worksheets ...
    (microsoft.public.access.externaldata)
  • Re: Excel ADO Crash
    ... One other important point: the recordset ... Dim cnt As New ADODB.Connection ... Set cnt = New ADODB.Connection ... Set rst = New ADODB.Recordset ...
    (microsoft.public.excel.programming)
  • Re: Booking System - Vacant room report
    ... in what format? ... within the date range as a field in the recordset, ... Dim colDates As Collection ... Set rst = CurrentDb.OpenRecordset ...
    (comp.databases.ms-access)
  • Re: Testing error code
    ... Dim rsDeclarationNo As Recordset ... Dim cmdDeclarationNo As Command ... .ActiveConnection = cnn ...
    (microsoft.public.vb.general.discussion)