Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If function not working (2003)

    Hi

    I am trying to check if a file exsists before executing the rest of the code. The file is a temp file only there if
    the real document is open. The file format looks like this ~$123456.doc the real file is 123456.doc

    Using FileLen or FileDateTime returns the correct data for the temp file but when the temp file is not there I
    get an error. On Error Resume Next doesn't seem to help.

    Now I am trying to use the following code still no luck.
    <pre>
    SecNo = SecNo + 1
    Section7:

    'Validate there is no temporary file open
    If dir(strPATH & "~$" & CRN & ".doc") = "" Then
    MsgBox "Document " & CRN & ".doc in location " & vbCrLf _
    & strPATH & vbCrLf _
    & "is open by another user please try again later.", vbInformation + vbOKOnly, _
    "Document already open"
    'Write to event log
    EventType = "Error"
    FaultCode = "0003"
    Call EventLog
    Exit Function
    End If
    On Error GoTo ErrHandler
    </pre>

    Regards
    Gerbil (AKA Kevin)

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

    Re: If function not working (2003)

    I think you've got the logic reversed. Dir(strPATH & "~$" & CRN & ".doc") = "" means that there is NO file ~123456.doc, i.e. the document itself is NOT in use.

  3. #3
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If function not working (2003)

    Yes I have didn't notice that but I have also tried

    If Not Dir(strPATH & "~$" & CRN & ".doc") = ""

    also with no luck, the only definate response I can get is

    If FileLen(strPATH & "~$" & CRN & ".doc") > 0 Then

    this works fine if the file is there but when its not I get an error, and using on resume next wont work.

    Any ideas?

    Thanks
    Regards
    Gerbil (AKA Kevin)

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

    Re: If function not working (2003)

    You can use this:

    Dim lngSize As Long
    On Error Resume Next
    lngSize = FileLen(strPATH & "~$" & CRN & ".doc")
    On Error GoTo ErrHandler
    If lngSize > 0 Then
    ' Document is open
    Else
    ' Document is not open
    End If

  5. #5
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If function not working (2003)

    Thanks Hans,

    Never thought about it that way
    Regards
    Gerbil (AKA Kevin)

Posting Permissions

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