RE: Export records into a text file based on criteria

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Thanks for the reply Joel.

I think the main problem will be that there will be over 50 of these files
being used and they all need to link back and update the same file.

The query doesn't timestamp anything. The data is imported into excel from
Access then the user makes any required changes.

"Joel" wrote:

Export CSV data is easy, the question how do you determine which cells havve
been updated. Does the querry produce a date on which cells were updated?

You could add a timestamp on you work*** when the last update was
perfromed and then import from access only items that havve changed since the
last update.

The CSV file could contain on the first line a date stamp so you know which
records need to be exported.

You need a more complete plan to determine which records need to be exported.


Here is some sample code

Sub WriteCSV()

Const MyPath = "C:\temp\"
Const WriteFileName = "text.csv"

Const Delimiter = ","

Const ForReading = 1, ForWriting = 2, ForAppending = 3

Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0


Set fswrite = CreateObject("Scripting.FileSystemObject")




'open files
WritePathName = MyPath + WriteFileName
fswrite.CreateTextFile WritePathName
Set fwrite = fswrite.GetFile(WritePathName)
Set tswrite = fwrite.OpenAsTextStream(ForAppending, TristateUseDefault)

LastRow = Cells(Rows.Count, "A").End(xlUp).Row

For RowCount = 1 To LastRow
LastCol = Cells(RowCount, Columns.Count).End(xlToLeft).Column
For ColCount = 1 To LastCol
If ColCount = 1 Then
OutputLine = Cells(RowCount, ColCount)
Else
OutputLine = OutputLine & Delimiter & Cells(RowCount, ColCount)
End If
Next ColCount
tswrite.writeline OutputLine
Next RowCount

tswrite.Close

Exit Sub
End Sub



"Maver1ck666" wrote:

I have an excel spread*** which imports data based on an MSQuery (refreshes
on open) which will provide a list of records.

What I want to do is this:

When a user updates a record, I would like Excel to export that complete
record into a central text file (comma delimited) on my network so we have a
log of what data was changed, time and who by.

Is this possible?
.


Quantcast