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

    Help with file not found (2003)

    Hi,

    Below is some code I use to open a word document based on information from the current record on an Access form. It works well, but when no file exsits I want it to display a msgBox telling me so. Currently it just does nothing, leaving you wondering weather the button was pressed or not!

    I have tried different If commands etc, but I don't the the code to use for when there is no such .doc at the location of strPath.

    Many thanks

    Private Sub CmdViewPatientLetters_Click()
    On Error GoTo Err_CmdViewPatientLetters_Click
    Dim strPath As String
    Dim intStart1 As Integer


    On Error Resume Next
    If (Left(Me.CRN, 1)) = "0" Then
    'Sets the path and opens the document
    intStart1 = CInt(Left(Me.CRN, 2))
    strPath = DLookup("Location", "TblFileLocations", "Description='Patient Letters'") _
    & DLookup("Specialty", "TblSpecialtyCodes", "SpecialtyCode= " & Chr(34) & Me.SPEC & Chr(34)) & "" & _
    "0" & intStart1 & "" & Me.CRN & ".doc"
    Application.FollowHyperlink strPath
    Else
    'Sets the path and opens the document
    intStart1 = CInt(Left(Me.CRN, 2))
    strPath = DLookup("Location", "TblFileLocations", "Description='Patient Letters'") _
    & DLookup("Specialty", "TblSpecialtyCodes", "SpecialtyCode= " & Chr(34) & Me.SPEC & Chr(34)) & "" & _
    intStart1 & "" & Me.CRN & ".doc"
    Application.FollowHyperlink strPath
    End If
    Exit Sub
    Err_CmdViewPatientLetters_Click:
    MsgBox "The file does not exsit", vbInformation, "File not found..."
    End Sub
    Regards
    Gerbil (AKA Kevin)

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

    Re: Help with file not found (2003)

    Above the lines with FollowHyperlink, insert
    <code>
    If Dir(strPath) = "" Then
    MsgBox "File " & strPath & " does not exist!", vbExclamation
    End If</code>

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

    Re: Help with file not found (2003)

    Thanks Hans,

    I forgot the 'dir' part!
    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
  •