Solved

vba save line into a flat file

Posted on 2012-03-12
4
414 Views
Last Modified: 2012-03-28
Hi,

I have a macro that goes through each name that is stated in the sheet and does a bunch of calculations etc...

Now I would like to create a log that will save a line per name that was run.  The only issue is that this macro is run by multiple users at the same time so I need a way to ensure that all lines are recorded.

I need to store only three things for each name it runs: name, username (computer name), date/time

the flat file will be ultimately used by another process done through the access database.

My biggest concern is if say two users are using the macro at the same time, how do i ensure that both macro's values are saved into the flat file?  Also what would be the most efficient way to save these lines into a text file?  

Please let me know if you need clarification.  Thank you!
0
Comment
Question by:iamnamja
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Expert Comment

by:armchair_scouse
ID: 37710681
Hmm...  what you are suggesting sounds overly complicated to me.  Could you not create a logfile per user, with the same generic name but then append the username to distinguish it (e.g. MyLogFile_Eric.txt, MyLogFile_Joanna.txt), and then you won't have the worry about multiple users writing to the same file at once?

You could then get your Access database to extract the values from the directory where you are storing your logfiles and get it to process all of the files that start with 'MyLogFile_'.

Just a thought :o)
0
 

Author Comment

by:iamnamja
ID: 37715395
the issue is... the process that writes to the log file is different than the process that reads it...

Since it locks when it's reading (from access) the issue occurs whenever someone opens the access database - which means the file is locked...  Then if someone tries to update the file while the database is open, it will keep the user from updaing the log file.
0
 
LVL 9

Expert Comment

by:armchair_scouse
ID: 37719563
OK, that issue wasn't clear from your original post.  If you are having problems with people being unable to access a log file/write to a log file whilst Access has it open, how are you accessing it from Access - is it attached as a linked table or are you opening the log file in code and processing the contents?  It sounds as though you are attaching the file as a linked table.

If you need to have the log files 'writeable', but still want to process the contents of the files in Access, could you perhaps create a table in your Access DB to hold log file data, then import the contents of the log file you want to process, and then just work off the data in the table?  That way you get the data you want to process in Access, and the users can still access their log files.
0
 
LVL 20

Accepted Solution

by:
ltlbearand3 earned 500 total points
ID: 37723349
To take what armchair_scouse has stated a step further, why not think about just writing the log data straight into Access instead of having an intermediate step.  If you can't have the data stored into the main access table/Database, then have the main database reference a different Access DB and have your log write straight to that DB.  When dealing with multiple users, you really should be using a Database instead of a text file.

-Bear
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question