Results 1 to 5 of 5
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    open colose event and txt file... (2000 sr-1)

    i have distribute to many user a wbook.
    In the event OPEN and CLOSE of workbook is present a sub my_macro and start when open or close the wbook.
    This macro write and update data in a txt file in myserverrmydirlog.txt.
    now my prob is....
    if all user open and close simultanious the wbook have a conflict?
    Suggest me...
    Is very important!
    Tks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: open colose event and txt file... (2000 sr-1)

    If you don't write a large amount of data to a text file, it is very fast with today's computers, so conflicts will be rare.

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: open colose event and txt file... (2000 sr-1)

    Hi Sal

    I suggest that you look at this post from <!post=Jan Karel Pieterse,654,278>Jan Karel Pieterse<!/post>.
    Regards
    Don

  4. #4
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: open colose event and txt file... (2000 sr-1)

    Hi Don
    nice....
    but admit have my file in c:mytxt.tx how to integrate the suggestion of Pieterse

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: open colose event and txt file... (2000 sr-1)

    The following code will try to write to the file up to 100 times before it gives up:

    Sub TestLog()
    Dim f As Integer
    Dim strFileName As String
    Dim intCount As Integer
    strFileName = "C:Mytxt.txt"
    Dim blnOpened As String
    On Error Resume Next
    f = FreeFile
    Do
    intCount = intCount + 1
    Err.Clear
    Open strFileName For Append As #f
    blnOpened = (Err = 0)
    DoEvents
    Loop Until Err.Number = 0 Or intCount = 100
    If blnOpened Then
    Print #f, "Test"
    Close #f
    Else
    MsgBox "Couldn't access log file!", vbCritical
    End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •