[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

11/04/2009 at 04:05AM PST, ID: 24870572 | Points: 500
[x]
Attachment Details

WIndows 7 - vba file lock

Asked by Billy_London in Windows 7, SBS Small Business Server

Tags: "windows 7" vba filesystem

I am running Office 2007 on Windows 7.
My Access application tries to write text to a file on a network share.
The first time it works. However, if the code tries to re-write the file, it comes up with a Path/File access error (75).
It can delete the file, just not recreate it.

I am running the code as a member of the administrators of the SBS 2003 domain.
The script to write the code is below - but this works fine on other computers.

Here's the strange thing: if I write to the file the first time from my Windows 7 machine, then log onto the file server and delete it, i CAN re-write it from the Windows 7 machine. It's only when the Windows 7 machine deletes it that it can't recreate it. somehow, it is creating a lock on a hypothetical file. The file server shows NO lock on this (non-existant) file when I go into the "Open Files" section of the "manage computer" console.

I have tried turning off the anti-virus (Kaspersky) but to no avail.
I have tried bypassing the code and manually creating the file in the directory, but I get a File In Use error from Windows 7:

The action can't be completed because the file is open in another program.
Close the file and try again
test.txt
Type: Text Document
Size: 0 bytes

Again, I checked the local "Open Files" list and nothing was listed.
If I bypass VBA, and manually create the file on Windows 7, then delete it, then I am able to recreate it. so maybe VBA creates things differently in Windows 7?

Is this a bug with Windows?

thanks

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Dim FileNumber As Integer 
On Error GoTo ErrorTrap 
FileNumber = FreeFile
If FileExists(pmFileName) Then Kill pmFileName
Open pmFileName For Output As FileNumber
Print #FileNumber, pmTextToWrite;
Close FileNumber 

FinishOff:
Exit Sub 

ErrorTrap:
MsgBox "Error writing text to file:" & vbCrLf & Err.Description
GoTo FinishOff
[+][-]11/04/09 06:22 AM, ID: 25739505

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 07:18 AM, ID: 25740151

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625