+ Reply to Thread
Results 1 to 6 of 6

Userform Combobox to display image name from file

  1. #1
    Registered User
    Join Date
    01-28-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2003
    Posts
    4

    Userform Combobox to display image name from file

    Hello,

    My user form titled "sinkinformation" has an image box and a combo box. I'd like the image box to display an image based on what is selected from combo box, titled "sinkstyle".

    The following is the code I am using. The problem I encounter is that the combo box will not display the list of file names from the file path specified in the code (C:\sinkstyle). Obviously this means that if the image's file name doesn't populate in the list, there's nothing to select to display that image.

    Please Login or Register  to view this content.

    I have checked the accuracy of the file path name, file type (.jpg), and other obvious possible errors which might cause this issue.

    Please let me know if any additional information is needed to better understand my question or code I am using.

    Thank you very much!
    Last edited by Leith Ross; 04-27-2013 at 04:22 PM. Reason: Added Code Tags

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Userform Combobox to display image name from file

    A Userform's initialize procedure is always called Private Sub Userform_Initialize() regardless of the form's name

    Try this...

    Please Login or Register  to view this content.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Userform Combobox to display image name from file

    Hello manda_w,

    In case you are interested in how to load a ComboBox using an Array, here is how...

    A 1-D (One dimensional) is considered to be a single row with multiple columns. But, you want each array element to represent a single row in your ComboBox list.

    There is a trick called transposing an array. This will switch the rows and columns of the array. That is the rows become the columns and the columns become the rows. This will convert your 1-D array into a 2-D array which you can then assign directly to the List property. This will automatically load the array contents into the ComboBox. Since the first subscript of the ComboBox is zero and the default first element of an array is zero, there is no need to start your array at position 1.
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 04-27-2013 at 09:34 PM.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    01-28-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Userform Combobox to display image name from file

    Both possible solutions solve the issue with the file names populating in the combo box, though shouldn't this following part of the code result in "image1" displaying the image of the file name selected from the combo box list?

    Please Login or Register  to view this content.
    I have tried a few other methods to tie an image to a selection, though referencing a .jpg via a file path is proving to be a bit more difficult.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Userform Combobox to display image name from file

    Hello manda_w,

    The LoadPicture statement expects the a Standard Picture. That is a bitmap, icon, or cursor image. The jpg file would need to be converted to be displayed correctly in the control.

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Userform Combobox to display image name from file

    The code in #2 worked for me using .jpg images.

    The UserForm_Initialize procedure I provided not only populates the combobox with the file name, it also puts the full file path of each image in a second hidden column within the combobx. That file path is referenced in my sinkstyle_change procedure.

    Did you use both my procedures together? Leith Ross's Initialize procedure does populate the combobox, but it does it differently than mine and is not intended to work with my sinkstyle_change procedure.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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