Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Export records into a text file based on criteria

I have an excel spreadsheet 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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Export records into a text file based on criteria

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 worksheet 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 spreadsheet 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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Export records into a text file based on criteria

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 worksheet 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 spreadsheet 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?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Export records into a text file based on criteria

You are right. There is going to be a sharing problem. What happends if two
people open two differrent files at the same time? Both are going to attempt
to open the same file, but only one will get write permission. The other is
going to get READ-ONLY permission.

"Maver1ck666" wrote:

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 worksheet 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 spreadsheet 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?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Export records into a text file based on criteria

the plan is to have a delay when excel tries writing the file if the text
file is locked (I have some code in another spreadsheet which already does
this).

"Joel" wrote:

You are right. There is going to be a sharing problem. What happends if two
people open two differrent files at the same time? Both are going to attempt
to open the same file, but only one will get write permission. The other is
going to get READ-ONLY permission.

"Maver1ck666" wrote:

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 worksheet 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 spreadsheet 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?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Export records into a text file based on criteria

You can use the following function to get the user name


Name = Environ("USERNAME")

Are you going to use a Button to determine when a record is updated or use
an event like worksheet_update to determine when the record is updated. Do
you plan to keep the CSV file opened when the 2nd workbook is opened or do
you plan to keep on opening and closing the CSV file for each updated record?

Do you need any additional help with the coding?
"Maver1ck666" wrote:

the plan is to have a delay when excel tries writing the file if the text
file is locked (I have some code in another spreadsheet which already does
this).

"Joel" wrote:

You are right. There is going to be a sharing problem. What happends if two
people open two differrent files at the same time? Both are going to attempt
to open the same file, but only one will get write permission. The other is
going to get READ-ONLY permission.

"Maver1ck666" wrote:

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 worksheet 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 spreadsheet 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?

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Export records into a text file based on criteria

Thanks for the environ code.

Not too sure how Excel would work out if the record has been updated or not?
Any suggestions on code would be a huge benefit.

The csv would have to be opened and closed I think in order to allow other
users changes that will need to be made.

Thanks again for your help, it is much appreciated ;)

Mav

"Joel" wrote:

You can use the following function to get the user name


Name = Environ("USERNAME")

Are you going to use a Button to determine when a record is updated or use
an event like worksheet_update to determine when the record is updated. Do
you plan to keep the CSV file opened when the 2nd workbook is opened or do
you plan to keep on opening and closing the CSV file for each updated record?

Do you need any additional help with the coding?
"Maver1ck666" wrote:

the plan is to have a delay when excel tries writing the file if the text
file is locked (I have some code in another spreadsheet which already does
this).

"Joel" wrote:

You are right. There is going to be a sharing problem. What happends if two
people open two differrent files at the same time? Both are going to attempt
to open the same file, but only one will get write permission. The other is
going to get READ-ONLY permission.

"Maver1ck666" wrote:

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 worksheet 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 spreadsheet 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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export to text file based on cell information Camron Excel Discussion (Misc queries) 0 July 24th 09 03:25 PM
how do I export excel records to csv file? 39steps Excel Discussion (Misc queries) 2 August 1st 07 01:34 PM
Cut Duplicate Records based on criteria Shiva Excel Programming 0 January 3rd 07 03:37 PM
Importing Text file based on criteria Martin Excel Discussion (Misc queries) 1 April 18th 06 07:20 PM
How do I export an excel file as fixed length records iainjh Excel Discussion (Misc queries) 2 March 3rd 05 05:59 PM


All times are GMT +1. The time now is 11:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"