none
Will not load my photo RRS feed

  • Question

  • i Followed the Instructions in a walkthrough guide to the T with few variations to suit my layout in my sheet and yet i cant seem to get the image in my user form to load like the directory is wrong or somthing of the sort , there is a tester peice of code that throws an error when no image loads and i have been ripping my hair out for 3 days (not an expert at this but tasked to work out of my scope) it is vb 7.1 . It is for a Ship Inspection my unit does once a year for 3 EX Warships im trying to make it easy to add the correct naming convention and image and be able to scroll through the images as needed but i cant get the dam thing to open the file i have i dont even know what i should remove at this point i have added and removed so much i figured it was time for help.

    Dim ImageName As String
    
    Private Sub GetImage()
        Dim ImageFolder As String
        Dim FilePath As String
        Dim FullImagePath As String
        
        '========================================'
        'GET THE IMAGE NAME AND IMAGE FOLDER NAME'
        '========================================'
        
        
        ImageName = ActiveCell.Offset(5, 2)
        ImageFolder = "Findings\"
        
        FilePath = NavigateFromWorkBookPath()
        '=================================='
        '   Get FULL PATH TO THE IMAGE     '
        '=================================='
        
        FullImagePath = FilePath & ImageFolder & ImageName
        
        '================================='
        '  LOAD IMAGE INTO PICTURE BOX    '
        '================================='
        If Dir(FullImagePath) <> "" Then
            Image1.Picture = LoadPicture(FullImagePath)
            Image1.PictureSizeMode = 3
        Else
            MsgBox "Could Not Load Image -No Such File"
        End If
        
    End Sub
    
    Private Function NavigateFromWorkBookPath() As String
        
        Dim WorkbookFolderPath As String
        Dim SlashPos As Integer
        Dim ImageFolderPath As String
        
        '======================================='
        '  GO ONE FOLDER UP FROM WORKBOOK PATH  '
        '======================================='
        WorkbookFolderPath = ThisWorkbook.Path
        SlashPos = InStrRev(WorkbookFolderPath, "\")
        ImageFolderPath = Left(WorkbookFolderPath, SlashPos)
    
        NavigateFromWorkBookPath = ImageFolderPath
    End Function
    
    Private Sub cmdLoad_Click()
         '=================================================='
        ' CHECK IF WE HAVE AN IMAGE NAME IN THE ACTIVE CELL'
        '=================================================='
        If ActiveCell.Column <> 2 Or ActiveCell.Row = 5 Or ActiveCell.Value = "" Then
    
        Cells(5, 2).Select
    
        End If
        
        '====================================================='
        ' GET DATA FROM SPREADSHEET AND PLACE INTO TEXTBOXES  '
        '====================================================='
        Call GetTextBoxData
        
        '=========================='
        ' SELECT AN OPTION BUTTON  '
        '=========================='
        Call GetOptionButtonValue
        
        '============================='
        ' LOAD AN IMAGE INTO IMAGE BOX'
        '============================='
        Call GetImage
        
        '========================================'
        ' SWITCH ON THE PREVIOUS AND NEXT BUTTON '
        '========================================'
        cmdBack.Enabled = True
        cmdNext.Enabled = True
        
    End Sub
    Private Sub GetTextBoxData()
        
        txtFileName.Text = ActiveCell.Offset(, 9)
        txtDate.Text = ActiveCell.Offset(, 2).Value
        txtInfo.Text = ActiveCell.Offset(, 3).Value
        txtDimensions.Text = ActiveCell.Offset(, 5).Value
        txtSize.Text = ActiveCell.Offset(, 6).Value
        txtCamera.Text = ActiveCell.Value

    Monday, January 16, 2017 8:53 PM

Answers

  • I apologize in advance if some of this is a bit elementary for you.

    (-) The file extension must match the extension of the file in the folder. We were using jpg as an example, but it could be gif, bmp, png, etc.

    To recap, your main sub should look like:

    Private Sub GetImage()
        Dim ImageFolder As String
        Dim FilePath As String
        Dim FullImagePath As String
        Dim strExtension as string
        
        '========================================'
        'GET THE IMAGE NAME AND IMAGE FOLDER NAME'
        '========================================'
        
        
        ImageName = ActiveCell.Value 'Not sure this is actually what you have'
        ImageFolder = "Findings\"
        
        FilePath = NavigateFromWorkBookPath()
        '=================================='
        '   Get FULL PATH TO THE IMAGE     '
        '=================================='
        
        FullImagePath = FilePath & ImageFolder & ImageName & "." & strExtension 
        
        '================================='
        '  LOAD IMAGE INTO PICTURE BOX    '
        '================================='
        If Dir(FullImagePath) <> "" Then  '<Set Breakpoint Here
            SET Image1.Picture = LoadPicture(FullImagePath)
            Me.Repaint
        Else
            MsgBox "Could Not Load Image -No Such File"
        End If
        
    End Sub

    
    

    (-) You should probably clear your breakpoints (Debug/Clear All Breakpoints), clear your watches - these seem to be confusing the issue at the moment. Then add only one breakpoint at the line

    If Dir(FullImagePath) <> "" Then

    You can run each statement one line at a time from that breakpoint by using "Debug/Step Into" or press F8 to see where the code execution goes. The statement that is on deck to be executed will be highlighted in yellow.

    (-) Also - When you say

    "still get my image cannot load else"

    I took it to mean that you are seeing the message "Could Not Load Image -No Such File". As a result, it is often easier to break the problem into separate parts - so the code I posted allows you to see what is going on only with the Dir() statement and the NavigateFromWOrkbookPath function without all the mess of opening the form. I've revised it just a little bit (above) so You can paste it in entirety into a new module. You can change the value of

    Const strHardcodedPath As String = "G:\TheExpectedPath\Findings\A test Image.jpg"


    to be anything you want it to be. In your case, I would make it
    Const strHardcodedPath As String = ""C:\Users\User\Desktop\Ship Inspection Program\Findings\FY-17_Ex-Texas_1.2.3_1_O1_Level_FR1_Engine Room.jpg"
    because you know that Dir() should result in some value.

    (-) Therefore, To run it, make sure your cursor is inside the CheckOutDir, and either click "Run/Run Form/Sub", or  push 'F5'. There are 2 checks:
    (i) If your hardcoded path is OK, then the filename will be shown above the 'Vs.". If the messagebox starts with "vs.", then the path/Imagename.Extension is probably a typo and you can work with File Explorer to work out what it should be.
    (ii) If there isn't anything listed after the 'Vs.", then the problem is with the path calculated by NavigateFromWOrkbookPath(), and you can see what is being calculated vs what should be working based on your (now working) hardcoded string.



    -MainSleuth You've Got It, Use It! Engineering, Science, Statistics Solutions http://ToolSleuth.com



    • Edited by MainSleuth Wednesday, January 18, 2017 11:50 AM
    • Marked as answer by Zebon Thursday, January 19, 2017 8:52 PM
    Tuesday, January 17, 2017 10:55 PM

All replies

  • Zebon,
    re: displaying pictures

    You can hide all your pictures on the worksheet and display them as needed, see...
    http://www.mcgimpsey.com/excel/lookuppics.html
    '---

    OR - Use an ImageList Control on a Userform...



    UPON REQUEST, I WILL MAKE THE WORKBOOK AVAILABLE FOR DOWNLOAD at DROPBOX (Link Shown Below)

    '---
    Jim Cone
    Portland, Oregon USA
    https://goo.gl/IUQUN2 (Dropbox)
    (free & commercial excel add-ins & workbooks)


    • Edited by James Cone Tuesday, January 31, 2017 3:10 AM
    Tuesday, January 17, 2017 12:13 AM
  • Hi Zebon,

    you need to debug your code.

    I find that it is not able to find the correct directory.

    as per your logic you believe that the folder should be available there but there is some issue with the path.

    so if folder is not available then you need to correct it in your code.

    please see the line mentioned below.

     WorkbookFolderPath = ThisWorkbook.Path
    
        SlashPos = InStrRev(WorkbookFolderPath, "\")
        ImageFolderPath = Left(WorkbookFolderPath, SlashPos)
    
        NavigateFromWorkBookPath = ImageFolderPath

    if workbook is not saved then when you execute "ThisWorkbook.Path". it will not return anything.

    so you will get messagebox that it is not able to find.

    in the second line it will search for "\" from right side.

    and go to 1 folder back.

    now here your folder should be available.

    debug it and check the location of folder in file explorer and correct it.

    after you able to find the correct folder check that image name is correct and it is available in that folder.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 17, 2017 1:34 AM
    Moderator
  • Hi Zebon

    you need to debug your code.

    I find that it is not able to find the correct directory.

    as per your logic you believe that the folder should be available there but there is some issue with the path.

    so if folder is not available then you need to correct it in your code.

    please see the line mentioned below.

     WorkbookFolderPath = ThisWorkbook.Path
    
        SlashPos = InStrRev(WorkbookFolderPath, "\")
        ImageFolderPath = Left(WorkbookFolderPath, SlashPos)
    
        NavigateFromWorkBookPath = ImageFolderPath

    if workbook is not saved then when you execute "ThisWorkbook.Path". it will not return anything.

    so you will get messagebox that it is not able to find.

    in the second line it will search for "\" from right side.

    and go to 1 folder back.

    now here your folder should be available.

    debug it and check the location of folder in file explorer and correct it.

    after you able to find the correct folder check that image name is correct and it is available in that folder.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    I Understand that it thinks the path is wrong the thing is i have the names and everything where it needs to be there is a sheets folder and a Findings folder the Code below

    If Dir(FullImagePath) <> "" Then
            Image1.Picture = LoadPicture(FullImagePath)
            Image1.PictureSizeMode = 3
        Else
            MsgBox "Could Not Load Image -No Such File"
        End If

     Seems to think that the path isnt there aswell but i cant seem to figure out why i have it refering to the correct cell i have many other modifications to make to the user form im just not sure what it is i missed i wonder if i can upload my entire folder to the drop box and ask for help. i dont like to ask for help but im crunched for time and a bit overly stressed about it lol. To top it off im doing it for free on my own time with a novice level of experience.

    btw my file paths are as follows it wouldnt let me post outside a code box so i jsut added it in there

    Sheet: C:\Users\User\Desktop\Ship Inspection Program\Inspection Sheet
    
    Pictures: C:\Users\User\Desktop\Ship Inspection Program\Findings


    Tuesday, January 17, 2017 12:59 PM
  • Zebon -

    A couple ideas that may help:

    (1) What is the value of "FullImagePath" at the line 
                    If Dir(FullImagePath) <> "" Then
    <To Get the value, set a breakpoint at that line. When the code interrupts, you can hover your mouse over that variable or you can right-click the variable name, select 'Watchlist', then click OK on the resulting dialog box. That opens the watchbox and you can see the value.>

     (2) When you get the value of ImageName in the line
     ImageName = ActiveCell.Offset(5, 2)
    are you getting both the Image Namand extension? (e.g. "MyGreatShipProfile" instead of "MyGreatShipProfile.jpg") You get nothing w/o the extension.



    -MainSleuth You've Got It, Use It! Engineering, Science, Statistics Solutions http://ToolSleuth.com

    Tuesday, January 17, 2017 2:00 PM
  • Zebon -

    A couple ideas that may help:

    (1) What is the value of "FullImagePath" at the line 
                    If Dir(FullImagePath) <> "" Then
    <To Get the value, set a breakpoint at that line. When the code interrupts, you can hover your mouse over that variable or you can right-click the variable name, select 'Watchlist', then click OK on the resulting dialog box. That opens the watchbox and you can see the value.>

     (2) When you get the value of ImageName in the line
     ImageName = ActiveCell.Offset(5, 2)
    are you getting both the Image Namand extension? (e.g. "MyGreatShipProfile" instead of "MyGreatShipProfile.jpg") You get nothing w/o the extension.



    -MainSleuth You've Got It, Use It! Engineering, Science, Statistics Solutions 

    holy shit the god dam file extension 

    The path is correct i forgot all about the watch setting so it now is having a failure to run the

    Image1.picture=LoadPicture(FullImagePath)

    If its not one thing its another

    • Edited by Zebon Tuesday, January 17, 2017 3:24 PM
    Tuesday, January 17, 2017 3:17 PM
  • That right there is worth the price of admission - As you said, if it ain't one thing, it's another. One step at a time, sometimes it's a slow slog.

    The line you indicated that has a problem needs a 'Set' statement if you're in vba:

        Image1.picture=LoadPicture(FullImagePath)

    should be

        SET Image1.picture=LoadPicture(FullImagePath)

    take a peek at the remarks in https://msdn.microsoft.com/en-us/library/aa264946%28v=vs.60%29.aspx?f=255&MSPPError=-2147217396


    -MainSleuth You've Got It, Use It! Engineering, Science, Statistics Solutions http://ToolSleuth.com

    Tuesday, January 17, 2017 4:00 PM
  • MainSleuth,

    I put SET Image1.picture=LoadPicture(FullImagePath) and read that link (thanks) and put 

    Set Image1.PictureSizeMode = 3 as the page said and get this error now Invalid use of property

    Tuesday, January 17, 2017 4:29 PM
  • You don't need 'Set' for the Image1.PictureSizeMode = 3.

    In fact, I'd comment out that whole line just to see if the image shows.

    You can select the Image1 control in the Userform, use the 'View/Properties' and set the PictureSizeMode directly w/o trying to code it.


    -MainSleuth You've Got It, Use It! Engineering, Science, Statistics Solutions http://ToolSleuth.com


    • Edited by MainSleuth Tuesday, January 17, 2017 4:55 PM Added screenshot
    Tuesday, January 17, 2017 4:42 PM
  • MainSleuth,

    Yea i t now is giving a path not found instead of the Else option i have no clue what i could have messed up been playing with it from 5 am untill now. When i hover over the file path it shows it it even shows it in the watch list just says path not found i have a named photo in there  and the names are the same in row 5 col 2 as FY-17  Ex-Texas 1.2.3  1  O1_Level  FR1  Engine Room.jpg  i even added .jpg to the image name so it would be 100% the same but no such luck im wondering is the part of the path its missing the file name or other?  

    I did remove the size var but to no avail

    Better yet is there a better way or easier to have it just go to that folder for the pictures? eventually the sheet is going to save new images to it too.

    a third thought did i somewhere there forget to refer to the image box?

    I would send a picture but im still not verified apparently so i cant



    • Edited by Zebon Tuesday, January 17, 2017 6:26 PM
    Tuesday, January 17, 2017 6:23 PM
  • after i realized i could watch the entire string there

    Watch : - : loadpicture : 0 : Object/Picture : UserForm1.GetImage

        : Handle : 0 : OLE_HANDLE : UserForm1.GetImage

        : Height : 0 : OLE_YSIZE_HIMETRIC : UserForm1.GetImage

        : hPal : <Automation error> : OLE_HANDLE : UserForm1.GetImage

        : Type : 0 : Integer : UserForm1.GetImage

        : Width : 0 : OLE_XSIZE_HIMETRIC : UserForm1.GetImage

    Tuesday, January 17, 2017 6:33 PM
  • so it should select the cell needed auto so activecell.offset(5, 2) not needed  i changed it to activecell.value im going to tried changing the naming convention to eliminate any spacing problem but it failed but looks clean 

    From : FY-17  Ex-Texas 1.2.3  1  O1_Level  FR1  Engine Room.jpg

    To     : FY-17_Ex-Texas 1.2.3_1_O1_Level_FR1_Engine_Room.jpg

    However after the offset was changed the error for the path disappeared so it is pathing to the correct folder but it just is not pulling the image to the image area, again to my question of did i forget a step to attach it to the photo frame

              

    Tuesday, January 17, 2017 6:59 PM
  • I wondered if the spaces would cause an issue. that's behind you, so it may be a simple matter of repainting the form:

    e.g.

     If Dir(FullImagePath) <> "" Then
            Image1
    .Picture = LoadPicture(FullImagePath)
            me.Repaint

    Figured you've been at it awhile

    -J


    -MainSleuth You've Got It, Use It! Engineering, Science, Statistics Solutions http://ToolSleuth.com

    Tuesday, January 17, 2017 7:29 PM
  • Yea its probably one of those looked at it to long things.

    me.Repaint  in watch

    Watch :   : Me.Repaint : <Expression not defined in context> : Empty : UserForm1.GetImage

    still get my image cannot load else

    Just cant figure it out the fullimagepath is correct its selecting the correct cell and everything have half a mind to upload this somewhere or to stream it on my broadcast tonight i bet its a simple issue im just not seeing it

    Tuesday, January 17, 2017 7:42 PM
  • (A) The Me.Repaint is a method - meaning an action - so the Watch isn't a value.

    I'm re-creating your structure for the NavigateFromWorkBookPath function will see how that is working.

    You can use this code to check that the paths are working. Pick an image file and enter the path and image name with extension into the strHardcodedPath const. Also check that the \Findings folder has appropriate permissions. DIR() respects those.

    Option Explicit
     Public Sub CheckOutDir()
         Const strHardcodedPath As String = "C:\Users\User\Documents\Findings\Default_Contrast.sm.gif"
         Dim strHardCodeResult As String
         Dim strPathTest As String
         Dim strPathResult As String
         strHardCodeResult = Dir(strHardcodedPath)
         strPathTest = NavigateFromWorkBookPath() & "Findings\Default_Contrast.sm.gif"
         strPathResult = Dir(strPathTest)
         MsgBox strHardCodeResult & vbCrLf & "vs. " & strPathTest & vbCrLf & "Yields:" & vbCrLf & strPathResult
     End Sub
     Private Function NavigateFromWorkBookPath() As String
         
         Dim WorkbookFolderPath As String
         Dim SlashPos As Integer
         Dim ImageFolderPath As String
         
         '======================================='
         '  GO ONE FOLDER UP FROM WORKBOOK PATH  '
        '======================================='
         WorkbookFolderPath = ThisWorkbook.Path
         SlashPos = InStrRev(WorkbookFolderPath, "\")
         ImageFolderPath = Left(WorkbookFolderPath, SlashPos)
    
        NavigateFromWorkBookPath = ImageFolderPath
     End Function
    



    -MainSleuth You've Got It, Use It! Engineering, Science, Statistics Solutions http://ToolSleuth.com








    • Edited by MainSleuth Tuesday, January 17, 2017 10:56 PM
    Tuesday, January 17, 2017 8:26 PM
  • So i just toggled a break and just realized full image path is comming up as "" i have full image path  set as: FullImagePath = FilePath & ImageFolder & ImageName

    When i togle break and run it to get it to where  can view the file path and what not FullImagePath when i hover over it says 

    FullImagePath= FilePath & ImageFolder & ImageName = false

    but thats only when i highlight it all each individual part is correct after the =

    Filepath is to the main folder image folder is to the Findings\ and ImageName is what is in the active cell

    Watch :   :         FullImagePath : "C:\Users\User\Desktop\Ship Inspection Program\Findings\FY-17_Ex-Texas_1.2.3_1_O1_Level_FR1_Engine Room.jpg" : String : UserForm1.GetImage

    Watch :   : FullImagePath : "C:\Users\User\Desktop\Ship Inspection Program\Findings\FY-17_Ex-Texas_1.2.3_1_O1_Level_FR1_Engine Room.jpg" : String : UserForm1.GetImage

    Watch :   : Me.Repaint : <Expression not defined in context> : Empty : UserForm1.GetImage

    removed the repaint and re added it and im 100% certian that i am getting the file path that is fixed

    its just not pasting to image1

    Tuesday, January 17, 2017 8:30 PM
  • im not 100% sure what your code does u put it in there with my path nothing seems to happen and the folder is just a normal folder no weird permissions or security things on it

    Tuesday, January 17, 2017 8:46 PM
  • I apologize in advance if some of this is a bit elementary for you.

    (-) The file extension must match the extension of the file in the folder. We were using jpg as an example, but it could be gif, bmp, png, etc.

    To recap, your main sub should look like:

    Private Sub GetImage()
        Dim ImageFolder As String
        Dim FilePath As String
        Dim FullImagePath As String
        Dim strExtension as string
        
        '========================================'
        'GET THE IMAGE NAME AND IMAGE FOLDER NAME'
        '========================================'
        
        
        ImageName = ActiveCell.Value 'Not sure this is actually what you have'
        ImageFolder = "Findings\"
        
        FilePath = NavigateFromWorkBookPath()
        '=================================='
        '   Get FULL PATH TO THE IMAGE     '
        '=================================='
        
        FullImagePath = FilePath & ImageFolder & ImageName & "." & strExtension 
        
        '================================='
        '  LOAD IMAGE INTO PICTURE BOX    '
        '================================='
        If Dir(FullImagePath) <> "" Then  '<Set Breakpoint Here
            SET Image1.Picture = LoadPicture(FullImagePath)
            Me.Repaint
        Else
            MsgBox "Could Not Load Image -No Such File"
        End If
        
    End Sub

    
    

    (-) You should probably clear your breakpoints (Debug/Clear All Breakpoints), clear your watches - these seem to be confusing the issue at the moment. Then add only one breakpoint at the line

    If Dir(FullImagePath) <> "" Then

    You can run each statement one line at a time from that breakpoint by using "Debug/Step Into" or press F8 to see where the code execution goes. The statement that is on deck to be executed will be highlighted in yellow.

    (-) Also - When you say

    "still get my image cannot load else"

    I took it to mean that you are seeing the message "Could Not Load Image -No Such File". As a result, it is often easier to break the problem into separate parts - so the code I posted allows you to see what is going on only with the Dir() statement and the NavigateFromWOrkbookPath function without all the mess of opening the form. I've revised it just a little bit (above) so You can paste it in entirety into a new module. You can change the value of

    Const strHardcodedPath As String = "G:\TheExpectedPath\Findings\A test Image.jpg"


    to be anything you want it to be. In your case, I would make it
    Const strHardcodedPath As String = ""C:\Users\User\Desktop\Ship Inspection Program\Findings\FY-17_Ex-Texas_1.2.3_1_O1_Level_FR1_Engine Room.jpg"
    because you know that Dir() should result in some value.

    (-) Therefore, To run it, make sure your cursor is inside the CheckOutDir, and either click "Run/Run Form/Sub", or  push 'F5'. There are 2 checks:
    (i) If your hardcoded path is OK, then the filename will be shown above the 'Vs.". If the messagebox starts with "vs.", then the path/Imagename.Extension is probably a typo and you can work with File Explorer to work out what it should be.
    (ii) If there isn't anything listed after the 'Vs.", then the problem is with the path calculated by NavigateFromWOrkbookPath(), and you can see what is being calculated vs what should be working based on your (now working) hardcoded string.



    -MainSleuth You've Got It, Use It! Engineering, Science, Statistics Solutions http://ToolSleuth.com



    • Edited by MainSleuth Wednesday, January 18, 2017 11:50 AM
    • Marked as answer by Zebon Thursday, January 19, 2017 8:52 PM
    Tuesday, January 17, 2017 10:55 PM
  • Hi Zebon,

    from the discussion it's looks like you are confused with the several things.

    here we are assuming various reasons for the issue but not sure what exactly it is.

    so first of all I would like to suggest you to follow the tutorials regarding loading the image in Image control in User Form.

    please visit the link below.

    Excel UserForm Controls - Image and RefEdit; use LoadPicture property with GetOpenFilename Method

    From link above you will get clear idea how to pass the path of an image.

    so try to pass it in your code directly and check it loads the image or not.

    then try to get the image name from the ActiveCell and try to append it with folder path and then again try to check whether it loads the image or not.

    so overall here I can see 2 major issue.

    (1) get the correct valid path with image name and extension.

    (2) load the image in image control.

    if you think that still you are not able to do what you want then just use the code mentioned below will solve your problem.

    no need to do anything with path.

    just click on button. it will open the open file dialog. you just need to select an image from file explorer and click ok.

    the image will be displayed in the image control.

    Private Sub cmdLoad_Click()
        Dim strFileName As String
        strFileName = Application.GetOpenFilename(filefilter:="Tiff Files(*.tif;*.tiff),*.tif;*.tiff,JPEG Files (*.jpg;*.jpeg;*.jfif;*.jpe),*.jpg;*.jpeg;*.jfif;*.jpe,Bitmap Files(*.bmp),*.bmp", FilterIndex:=2, Title:="Select a File", MultiSelect:=False)
            If strFileName = "False" Then
                MsgBox "File Not Selected!"
            Else
                Me.Image1.Picture = LoadPicture(strFileName)
                Me.Repaint
            End If
    End Sub

    below is my form:

    if you want to select different types of image then just need to make changes in "file filter" in above code.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 18, 2017 2:15 AM
    Moderator
  • I apologize in advance if some of this is a bit elementary for you.

    (-) The file extension must match the extension of the file in the folder. We were using jpg as an example, but it could be gif, bmp, png, etc.

    To recap, your main sub should look like:

    Private Sub GetImage()
        Dim ImageFolder As String
        Dim FilePath As String
        Dim FullImagePath As String
        Dim strExtension as string
        
        '========================================'
        'GET THE IMAGE NAME AND IMAGE FOLDER NAME'
        '========================================'
        
        
        ImageName = ActiveCell.Value 'Not sure this is actually what you have'
        ImageFolder = "Findings\"
        
        FilePath = NavigateFromWorkBookPath()
        '=================================='
        '   Get FULL PATH TO THE IMAGE     '
        '=================================='
        
        FullImagePath = FilePath & ImageFolder & ImageName & "." & strExtension 
        
        '================================='
        '  LOAD IMAGE INTO PICTURE BOX    '
        '================================='
        If Dir(FullImagePath) <> "" Then  '<Set Breakpoint Here
            SET Image1.Picture = LoadPicture(FullImagePath)
            Me.Repaint
        Else
            MsgBox "Could Not Load Image -No Such File"
        End If
        
    End Sub

    
    

    (-) You should probably clear your breakpoints (Debug/Clear All Breakpoints), clear your watches - these seem to be confusing the issue at the moment. Then add only one breakpoint at the line

    If Dir(FullImagePath) <> "" Then

    You can run each statement one line at a time from that breakpoint by using "Debug/Step Into" or press F8 to see where the code execution goes. The statement that is on deck to be executed will be highlighted in yellow.

    (-) Also - When you say

    "still get my image cannot load else"

    I took it to mean that you are seeing the message "Could Not Load Image -No Such File". As a result, it is often easier to break the problem into separate parts - so the code I posted allows you to see what is going on only with the Dir() statement and the NavigateFromWOrkbookPath function without all the mess of opening the form. I've revised it just a little bit (above) so You can paste it in entirety into a new module. You can change the value of

    Const strHardcodedPath As String = "G:\TheExpectedPath\Findings\A test Image.jpg"


    to be anything you want it to be. In your case, I would make it
    Const strHardcodedPath As String = ""C:\Users\User\Desktop\Ship Inspection Program\Findings\FY-17_Ex-Texas_1.2.3_1_O1_Level_FR1_Engine Room.jpg"
    because you know that Dir() should result in some value.

    (-) Therefore, To run it, make sure your cursor is inside the CheckOutDir, and either click "Run/Run Form/Sub", or  push 'F5'. There are 2 checks:
    (i) If your hardcoded path is OK, then the filename will be shown above the 'Vs.". If the messagebox starts with "vs.", then the path/Imagename.Extension is probably a typo and you can work with File Explorer to work out what it should be.
    (ii) If there isn't anything listed after the 'Vs.", then the problem is with the path calculated by NavigateFromWOrkbookPath(), and you can see what is being calculated vs what should be working based on your (now working) hardcoded string.



    -MainSleuth You've Got It, Use It! Engineering, Science, Statistics Solutions 


    ive tried it the extension just reads out as "" and im still not getting how to use the checker code you made there.

    I may just need to throw in the towel i know this works ive seen someone use the identical code aside from the names in another sheet before but yet it isnt working now, i disabled the auto save

    It pulls the image name from the active cell in the spreadsheet so the name is correct i copy pasted into the image name

    No freakin clue why its just not filling the image box  i am getting the message box you said about btw my box  

    Else
            MsgBox "Could Not Load Image -No Such File"
        End If

    That is popping up everytime but when i hover over every single thing else such as the FullImagePath items everything is correct aside from the new introduction of strExtension nothing shows there aside from ""  and full image path in the Set Image1.Picture= LoadPicture(FullImagePath) or rather all Full image Path's in this Sub show 100% the correct path , the user form image box im afraid is where i dont see the image I did look at the other guys post but that is the opposite of what im trying to acomplish here. 

    I rechecked on my first version of this and the path was correct all the way through aswell but the Image box on the user form remains blank  I wanna make sure that im not being confusing on what im talking about

    Thursday, January 19, 2017 5:46 PM
  • Deepak,

    Im not sure if your following what my issue is exactly, all of the path's are squared away and mapped where they need to be and reading correctly, it takes the name from the spreadsheet and uses that name to coinside with the name in the folder(i copy/pasted to make 100% same with no phantom spaces)  for whatever reason either i missed the part in my code where it says "Hey image box take this pic please and display it when i click load"

    Thursday, January 19, 2017 5:50 PM
  • so i am a freakin idiot lol it was the simplest fix after the last few days i opened previous version 

    Im going to load the code and see if you can see the idiotic thing i missed that MainSleuth 's Post reminded me of. I knew i couldnt be this stupid 

    Private Sub GetImage()
        Dim ImageFolder As String
        Dim FilePath As String
        Dim FullImagePath As String
        
        
        '========================================'
        'GET THE IMAGE NAME AND IMAGE FOLDER NAME'
        '========================================'
        
        
        ImageName = ActiveCell.Value 'Not sure this is actually what you have'
        ImageFolder = "Findings\"
        
        FilePath = NavigateFromWorkBookPath()
        '=================================='
        '   Get FULL PATH TO THE IMAGE     '
        '=================================='
        
        FullImagePath = FilePath & ImageFolder & ImageName & ".jpg"
        
        '================================='
        '  LOAD IMAGE INTO PICTURE BOX    '
        '================================='
        If Dir(FullImagePath) <> "" Then  '<Set Breakpoint Here
            Set Image1.Picture = LoadPicture(FullImagePath)
            Image1.PictureSizeMode = 3
        Else
            MsgBox "Could Not Load Image -No Such File"
        End If

    heres a hint

    ".jpg"

    • Edited by Zebon Thursday, January 19, 2017 6:28 PM
    Thursday, January 19, 2017 6:20 PM
  • Good to hear you have it figured out!

    -MainSleuth You've Got It, Use It! Engineering, Science, Statistics Solutions http://ToolSleuth.com

    Thursday, January 19, 2017 6:55 PM