Results 1 to 5 of 5
  1. #1
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376

    Gett Error 2220 when try to add an image

    Hello all,

    I am trying to load an image file and I get an Error 2220. The code is as follows. I know it is the line "Me.LogoImage.Picture = Me.OrgLogoPath" that is causing the error but I don't understand what is going wrong. when I debug the line OrgLogoPath = the path to the file but Me.LogoImage.Picture = "None".


    Private Sub cmdAddLogo_Click()


    On Error GoTo SubError
    'Add "Microsoft Office 14.0 Object Library" in references


    Dim fDialog As Office.FileDialog
    Dim varFile As Variant

    OrgLogoPath = ""

    ' Set up the File Dialog
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

    With fDialog
    .Title = "Choose the Image you would like to Use"
    .AllowMultiSelect = False
    ' .InitialFileName = "C:\Users\ray\Desktop\Export to Excel" 'Folder picker needs trailing slash

    .Filters.Clear
    ' .Filters.Add "Excel files", "*.xls*"
    ' .Filters.Add "Excel files", "*.xls"
    ' .Filters.Add "Excel files", "*.xlsx"
    ' .Filters.Add "Excel macro-enabled", "*.xlsm"

    If .Show = True Then
    If .SelectedItems.Count = 0 Then
    'User clicked open but didn't select a file
    GoTo SubExit
    End If

    'An option for MultiSelect = False
    'varFile = .SelectedItems(1)
    'txtSelectedName = varFile

    'Needed when MultiSelect = True
    For Each varFile In .SelectedItems
    OrgLogoPath = OrgLogoPath & varFile & vbCrLf
    Me.LogoImage.Picture = Me.OrgLogoPath

    Next
    Else
    'user cancelled dialog without choosing!
    'Do you need to react?
    End If

    End With

    SubExit:
    On Error Resume Next
    Set fDialog = Nothing
    Exit Sub

    SubError:
    MsgBox "Error Number: " & Err.Number & " = " & Err.Description, vbCritical + vbOKOnly, _
    "An error occurred"
    GoTo SubExit


    End Sub

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    What I wonder about is
    a) your comments state that a trailing slash is required but you don't seem to be adding it anywhere
    b) why you would put a line feed and carriage return in the file path
    c) why have a loop for the dialog when you set multi select to no. Simply test if .Show value is 0 or -1 (not picked or picked)
    Your path string might contain invalid characters because of c) or be missing the slash and you haven't noticed.

    Please post your code within code tags to format for easier reading.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    In addition to Microns observations it appears you do not have option explicit declared in the declarations as I dont see where you dimension OrgLogoPath.

    Save yourself some time \ troubles in the future and create a public filedialog procedure in a standard module.
    That way you can simplify the code in your form module
    Code:
    Private Sub cmdAddLogo_Click()
    
         Me.LogoImage.Picture = TheNameOfYourPublicFunction
    
    End Sub
    It is also very helpful to add a Debug.Print for the result of your Filedialog function so you can see if it is properly formatted.

    Edit: heres a very basic filedialog file picker procedure
    Code:
    Public Function GetFilePath() As String
    
    
        Dim strFilePath As String
    
    
       On Error GoTo GetFilePath_Error
    
    
        With Application.FileDialog(msoFileDialogFilePicker)
    
    
            If .Show <> 0 Then
                strFilePath = .SelectedItems(1)
            End If
            
        End With
        
        Debug.Print strFilePath    ' remove in production
        
        GetFilePath = strFilePath
    
    
       On Error GoTo 0
       Exit Function
    
    
    GetFilePath_Error:
    
    
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure GetFilePath of Module Module1"
    
    
    End Function
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    moke123,

    I was going to put it into a module once i got it working the way I wanted to so I could reuse it because I want to down the road a bit. I took your code and used it but when I try to put the result into the txtOrgLogoPath Field it doesn't persist. Also I want to be able to have different images for different records so I want the value of LogoImage.Picture to be the path in txtOrgLogoPath, does that makes sense?

    I have attached zip file with a copy of the database. I am just having a mental block on this for some reason.

    DaveImageIssue.zip

    Thanks for the assistance

    Dave

  5. #5
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    I believe I have got it resolved. Now I can have a different picture for each different record. Thanks for the assistance.

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

Similar Threads

  1. Replies: 6
    Last Post: 09-18-2020, 09:06 PM
  2. Replies: 5
    Last Post: 07-10-2020, 12:41 PM
  3. Image. Error Use of Null.
    By Perfac in forum Programming
    Replies: 10
    Last Post: 02-17-2018, 12:40 PM
  4. Replies: 1
    Last Post: 11-28-2014, 06:56 PM
  5. Intercepting error codes like 2220, file not found
    By justphilip2003 in forum Programming
    Replies: 4
    Last Post: 04-21-2013, 11:33 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