Results 1 to 4 of 4
  1. #1
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    GetFileInformation runtime error '5' when cancel


    Hello!

    I am using the following function to find and link pictures in my database. It works fine, however, if I decide not to attach a picture and choose "cancel" from the window, I get the message "Runtime Error '5' Invalid call or procedure". This will confuse users. I'm don't know how to get around it and am looking for direction. Thank you in advance.
    Code:
    Public Function GetFileInformation(strPathAndFileName As String)
    On Error GoTo errHandler
    
    Dim I As Integer, J As Integer, intCurrPos As Integer, intNextPos As Integer
    Dim intFinalPos As Integer, intLength As Integer
    intCurrPos = 1
    intLength = Len(strPathAndFileName)
        For I = 1 To intLength Step intCurrPos
            intNextPos = InStr(intCurrPos + 1, strPathAndFileName, "\")
            If intNextPos = 0 Then
               glFileName = Mid(strPathAndFileName, intCurrPos + 1, intLength)
               intFinalPos = intCurrPos
            End If
            intCurrPos = intNextPos
        Next I
        glPath = Mid(strPathAndFileName, 1, intFinalPos - 1)
        glInitDir = glPath
        Exit Function
    errHandler:
        MsgBox "Error " & Err.Number & ": " & Err.Description & " in " & _
               VBE.ActiveCodePane.CodeModule, vbOKOnly, "Error"
    
    End Function

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    How is it possible to choose Cancel?

  3. #3
    Gina Maylone is offline Always learning
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Click image for larger version. 

Name:	file.JPG 
Views:	5 
Size:	59.2 KB 
ID:	22287
    Cancel is here on the file dialog. Thanks!

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Don't allow the user to call the function if the user cancels the file dialog.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 08-22-2015, 11:26 AM
  2. Replies: 4
    Last Post: 10-24-2014, 12:39 PM
  3. Replies: 4
    Last Post: 12-30-2013, 05:51 PM
  4. Replies: 13
    Last Post: 06-12-2012, 09:52 PM
  5. Replies: 0
    Last Post: 03-11-2012, 09:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums