Error 55 problem

R

Reg

I have made a small Access database for my daughter to use at her work to
send and store emails. It uses code I have found on the www and behaves fine
when I use it, but gives an error when she tries to use it.
My default email client is Outlook Express and hers is Outlook but the error
seems to occur before Outlook is opened

At one point the code is as follows
Private Function EmailCreate(sTmpFile) As Long
Dim hFile As Long
hFile = FreeFile
Open sTmpFile For Output As #hFile
EmailCreate = hFile
End Function

She gets an Error 55 (file already open) at the line
Open sTmpFile For Output As #hFile

Stepping through the code she sees hFile is intially 0 and then becomes 1
when it is assigned a FreeFile

I would be grateful if someone could explain what is causing this error.

Thanks
 
D

Douglas J Steele

The error is trying to tell you that the file is already opened.

Are you closing the file properly after you write to it? Might there be
other applications that have a handle on the file?
 
R

Reg

Thank you Doug
The form works fine on my computer. The code does not open the file to write
to prior to this. It is designated
thus:
sTmpFile = "C:\temp.eml"

She has now been able to get the form to run properly after I instructed her
to find and delete that file. I should have got her to send me a copy of it
to see what was in it, but neglected to do so.
However, I have another couple of questions arsing from this that would help
me understand what is happening.
Am I right in thinking that if another application had a handle on the file
she would not have been able to delete it?
I think that perhaps she aborted an earlier running of code from the form,
but left Access and the form open and then tried to run the code from the
form again and got that error message. In other words she still had another
copy of the form open.
Does that sound like a possible explanation to you?

To prevent this happening again, would it be ok and effective to put a Close
command in like this:

hFile = FreeFile
Close #hFile
Open sTmpFile For Output As #hFile

Reg
 
D

Douglas J Steele

Yes, aborting a previous run could cause the problem. However, your proposed
solution won't work. FreeFile simply gives you a file handle. It's the file
itself that's locked, nothing to do with whatever file handle FreeFile gives
you. (In fact, since whatever handle is still attached to the file isn't
free, FreeFile is guaranteed not to return the "problem" file handle to
you). The easiest solution would be to reboot the computer.

How are you writing to the file? You should open the file, write to it, then
close the file. If you're keeping it open for the duration of the execution
of the program, you'll likely run into this problem again.
 
R

Reg

Thanks Doug
That's very helpful. The file is closed immediately I have finished writing
to it :)
Reg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top