+ Reply to Thread
Results 1 to 14 of 14

Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserForm

  1. #1
    Registered User
    Join Date
    04-09-2017
    Location
    Los Angeles, USA
    MS-Off Ver
    2010
    Posts
    8

    Question Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserForm

    Hi guys,

    I'm new here and sort of new to VBA as well.
    I have a worksheet with two columns. Column A contains a ID number, and Column B contains a hyperlink path to the image.
    I have also created a userform with a combobox and an imagebox. When I click on the combo box, it will show me the ID number and when selected, it should show me the corresponding image.
    However, my problem right now is that the hyperlink path in Column B is an absolute path (K:\test\Images\image1.jpg). I would like a relative path so that when I switch computers (these files are all contained on my usb stick), they will still work.
    I've tried going into properties and setting the Hyperlink Base to K:\test\Images\ and then in Column B just Inserting a Hyperlink with just the image file name. And for one night, the userform worked with the hyperlink base set and with just the image file name. Then it stopped working consequently. I'm not really sure how to proceed from here.

    This is an image of what I have at the moment...as you can see it displays the full path selection properly but if I click on the other ID numbers no image shows up. Right now the file properties has a Hyperlink Base set to "K:\test\Images\", just so you are aware.
    Excel Forum Post Image.jpgExcel Forum Post Image2.jpg

    At any rate, this is the code I have at the moment, and it works for absolute paths, just not relative paths. I'm not sure what changed overnight.

    Please Login or Register  to view this content.
    Is there additional code I need to insert?


    EDIT: For my combobox1 I have given a name to the rowsource in the properties settings. There are two names if you check under the formula tab>name manager. I used "imagetest" in this case which is the green highlighted area.

    Thanks in advance,
    remixboy.
    Attached Files Attached Files
    Last edited by remixboy; 04-22-2017 at 04:20 AM. Reason: Additional Information

  2. #2
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserF

    You need a unique ID for each photo in order to display them
    In Column A you may add any type of ID other than numbers but it should be unique for each photo
    then you need to rename your picture folder to "Photos" and keep that folder into the same directory where your workbook resides.All photos of your folder should be renamed according to the unique IDs in column A.In column B you may add some description of the photo (optional)
    the code will look like this

    Please Login or Register  to view this content.
    See attachment

    Best Regards
    Imran Bhatti
    Last edited by ImranBhatti; 04-15-2017 at 03:55 AM.
    Teach me Excel VBA

  3. #3
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserF

    Unable to attach sample photos folder.
    Here is the workbook with modified userform code.You may add the folder of your own photos but that folder should be renamed as "Photos" and all the photos inside that folder should be renamed according to the Unique IDs in column A and place the "Photos" folder in the same directory where your workbook resides.

    Hope this helps
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    04-09-2017
    Location
    Los Angeles, USA
    MS-Off Ver
    2010
    Posts
    8

    Re: Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserF

    Thanks ImranBhatti, but that's not what I'm looking for. In my actual workbook, I have unique ID's (more than just 1's and 2's) in Column A. And in Column B I have absolute paths to each file. I do not want to rename each image file the same as the unique ID in Column A. I need to have them be as they are. The two columns have to remain unique. I would just like the hyperlink base function to work. The image folder is in the same directory as my workbook. This workbook I've uploaded is just a simple recreation of the actual workbook without all the private information. I'll play around with your code for now. It's late I need to sleep. Thanks again for the help.

  5. #5
    Registered User
    Join Date
    04-09-2017
    Location
    Los Angeles, USA
    MS-Off Ver
    2010
    Posts
    8

    Re: Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserF

    Hello? Anyone else with ideas?

  6. #6
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserF

    Hi remixboy

    your code
    Please Login or Register  to view this content.
    is working for me.just refresh your hyperlinks in the green section.

  7. #7
    Registered User
    Join Date
    04-09-2017
    Location
    Los Angeles, USA
    MS-Off Ver
    2010
    Posts
    8

    Re: Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserF

    Hi Imran,

    I just deleted all the hyperlinks and re-added them to the green section. Still no luck of them showing up on the userform when i select them from the ComboBox. Is there a setting I messed up? I have the hyperlink base set to K:\test\Images\ and i've inserted just the file names. it should in theory work, but it seems only absolute referencing of the files work. There's something missing in this picture.....

  8. #8
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserF

    Do you see an error message? if yes what is the error message?

  9. #9
    Registered User
    Join Date
    04-09-2017
    Location
    Los Angeles, USA
    MS-Off Ver
    2010
    Posts
    8

    Re: Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserF

    That's the issue. I don't see ANY messages. The code is fine. It works perfect for absolute paths, just not for Hyperlink Base. In the green area I have an absolute path just to test and make sure everything's working and then everything else onward is based off the hyperlink base which i've set up in the document properties. So in theory, all I have to do is insert the filename.jpg and it should still show up in my my imagebox when the ID number in column A is selected from the comboBox. But no, to answer your question, i don't see any error messages.

  10. #10
    Registered User
    Join Date
    04-09-2017
    Location
    Los Angeles, USA
    MS-Off Ver
    2010
    Posts
    8

    Re: Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserF

    Okay, After taking out On Error Resume Next and clicking on an ID that has just a file name and not an absolute path, this error shows up:

    Excel Forum Post Image3.jpg

  11. #11
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserF

    So the linked picture might have been moved/deleted.

  12. #12
    Registered User
    Join Date
    04-09-2017
    Location
    Los Angeles, USA
    MS-Off Ver
    2010
    Posts
    8

    Re: Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserF

    Impossible. It's right there in the folder. But I seem to have solved the mystery for now. We'll see how well it holds up against the test of time.
    Here is the original code:
    Please Login or Register  to view this content.
    And here's what I tweaked...
    Please Login or Register  to view this content.
    This seems to work well so far. It's displaying all the image files I throw at it plus I don't have to make the image file names the same name as my ID/PIN.

  13. #13
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserF

    Glad to know that you resolved the issue yourself.

  14. #14
    Registered User
    Join Date
    04-09-2017
    Location
    Los Angeles, USA
    MS-Off Ver
    2010
    Posts
    8

    Re: Need Help dsplaying an image in an Image1 based off selection from ComboBox in a UserF

    Thanks for your help! I'll mark this as solved then. Case closed.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Userform Toggle or Option button based on Listbox selections
    By KML1976 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-31-2016, 10:52 AM
  2. Dynamic autofilter based on user selections on userform with chkboxes...
    By Sravanmonty in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-21-2014, 06:39 AM
  3. Displaying image based on cell value
    By gsrai31 in forum Excel General
    Replies: 0
    Last Post: 05-22-2012, 06:52 PM
  4. Displaying and Updating Image Dynamically (ActiveX Image Control?)
    By VTHokie11 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2011, 10:57 AM
  5. Userform - Picture inserted into image1 control based on what is populated into t
    By johncembree in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2010, 03:44 AM
  6. Replies: 2
    Last Post: 08-02-2010, 09:45 AM
  7. Displaying a random image (or control) on a userform?
    By Jon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-30-2006, 01:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1