File Already Open

ukjock
05-13-2003, 07:12 AM
Does anybody know how to get around this error???

I have to read/write info to a file which 2 programs are reading from and 1 is writing to.

If i try and use the writing program to save to a file which the other 2 programs are reading from. I get an error on the writing program sayin "File Already Open" and crashes the writing program.

Is there any way to get round this???

also

if i append a file is there anyway to get the information to sit above the current info in the file??

Am i asking for to much?? lol

Thanks for your help.

Chris

vbfan
05-13-2003, 07:50 AM
have you close the File after you had read it, in your reading app?
Or generally have you close all files after you have read/write it?

Banjo
05-13-2003, 08:25 AM
The more concise answer is no, you can not write to a file while others are reading from (or writing to) it. You can avoid that crash by using an error handler something like this:
On Error Goto UnableToWrite
Print #1, "blah blah blah"
On Error Goto 0

' Rest of sub goes here

Exit Sub

UnableToWrite:
' What do you here is up to you.
' Option 1 is to just inform the user that there was a problem writing
Msgbox "Unable to save the file. Other users may have it open!", vbExclamation

' Option 2 is to just try again and keep trying until you succeed.
Resume
End Sub

ukjock
05-13-2003, 11:45 AM
Thanks guys can this work inside a function as well???

Chris

vbfan
05-13-2003, 01:48 PM
When you mean If banjo's code can work in a Function, too.
Yes it can.
You only need to change the all words Sub to Function and not more.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum