LITTLEBLACKDOG.COM Forum Index LITTLEBLACKDOG.COM

 
LWD LWD   FAQ FAQ   Memberlist Memberlist   Usergroups Usergroups   Active Topics Active Topics   Register Register  
  Profile Profile   Log in to check your private messages Log in to check your private messages   Log in Log in  
  Who is Online Who is Online   Image Gallery Image Gallery   Chat Chat   Search Search  
  LWDGear       LBDGear  

View next topic
View previous topic
Post new topic     Reply to topic   LITTLEBLACKDOG.COM Forum Index » Code Warriors
Author Message
dstg_ll
-=* NSFW *=-
-=* NSFW *=-


Joined: 14 Jun 2002
Age: 33
Posts: 14105
Location: Black Pearl

Post Posted: Tue Mar 24, 2009 10:28 am   Post subject: [VBA] OPEN FOR with network file ? Reply with quote Back to top  

Can't find anything on the net, so i'll try here...

When i use this line of code in VBA (Word 2003) :

Code: Select all
fnum = FreeFile()
Open MyFile For Append Shared As fnum


... on a file that's on the network \\somewhere\somefolder\somefile.txt\ , the file is locked when another user tries to write in the same file (with the same macro). I can't delete or write in that file unless i go on the computer that just ran the macro and delete it manually.

How can i unlock the file so everyone can write in it ? Is there a way to do this ?
View user's profile Send private message Visit poster's website
anglachel
Guide Dog
Guide Dog


Joined: 08 Nov 2003
Posts: 9129
Location: MN

Post Posted: Tue Mar 24, 2009 12:13 pm   Post subject: Reply with quote Back to top  

do you close the file when your done?

Something like "MyFile.close".

_________________

Quidquid latine dictum sit, altum sonatur.
Death to Shuttleworth!
View user's profile Send private message AIM Address
dstg_ll
-=* NSFW *=-
-=* NSFW *=-


Joined: 14 Jun 2002
Age: 33
Posts: 14105
Location: Black Pearl

Post Posted: Wed Mar 25, 2009 5:55 am   Post subject: Reply with quote Back to top  

Yes... Close #fnum

Here's the whole code:



Code: Select all
Private Sub btnSave_Click()

Dim myDate
Dim myTime
Dim txtNow As String
Dim Msg, Style, Title, Help, Ctxt, Response, MyString

MyFile = "\\Nas1-6ea\CORR\" & "CORRectionsTM_ALL.txt"

myDate = DateValue(Now)
myTime = TimeValue(Now)
txtNow = Format(myDate, "dddd d mmm yyyy") + ", " + Format(myTime, "Hh:Mm:Ss")

'set and open file for output
fnum = FreeFile()
Open MyFile For Append Shared As fnum
    Print #fnum, "*************************************************************************"
    Print #fnum, "<Demandeur> " + txtDemandeur.Text
    Print #fnum, "<Corrigé le> " + txtNow
    Print #fnum, "<Corrigé par> " + cbUSER.Text
    Print #fnum, ""
   
    Print #fnum, "<Mémoire(s) Corrigée(s)> " + txtMem.Text
   
    Print #fnum, ""
   
    Print #fnum, "<Source> " + txtSource.Text
    Print #fnum, "<Erreur> " + txtOld.Text
    Print #fnum, "<Correction> " + txtCorr.Text
    Print #fnum, "*************************************************************************"
    Print #fnum, ""
    Print #fnum, ""
   
Close #fnum


Msg = "Correction sauvegardé dans le fichier: " + MyFile + vbCrLf + vbCrLf + "Voulez-vous entrer une autre correction ?"    ' Définit le message.
Style = vbYesNo + vbQuestion + vbDefaultButton2
Title = "Opération Terminé !"

' Affiche le message.
Response = MsgBox(Msg, Style, Title)
If Response = vbNo Then    ' L'utilisateur a choisi Non.
    End    ' Effectue une action.
End If

End Sub
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic     Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
phpBB SEO
All times are GMT - 8 Hours

Help us keep advertisements off this site. Donate today!