• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

write to a file that is already open?

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

medo145

Member
Joined
Jun 11, 2004
Here's the scenario.

We have a log on/off script that logs who logs in and out on what computer at what time. I like to use that file when I need to help someone, but it's tedious to have to go to the end of the text document, control+F, change the search direction and enter the person's username.

To make searching easier, I made an access document and linked the txt file to it as a table. made a form to search for a user's last record.

Here's the problem. Once the access document is opened, the script is unable to write to the txt file. This wasn't a problem before when just opening the txt file, because the scrip was still able to write to the file and reopening the txt would show the new records.

So my question is, is it somehow possible to have the txt linked into access and have the script be able to write to the txt file while the access doc is open? Is there another solution to achieve what I'm trying to do? Is it possible to make the script add the new entry to the first line of the txt instead of the last?

Thanks
 
That's a really silly way to go about finding the last record... :)
Code:
grep username file | tail -n1

Or, if this is a Windows system (suggested by Access), using a PowerShell script:
Code:
get-content file | where {$_ -match "username"} | select-object -last 1
 
Last edited:
thanks, the powershell script works, but it's inconvenient to have to change the script every time I want to look up a user. Is it possible to have the script ask the value of the username field once it is run?


edit:
figured it out

Code:
$a = read-host "search"
get-content file | where {$_ -match "$a"} | select-object -last 1
 
Last edited:
Back