Solved

Load Image from Listbox Change Event

Posted on 2013-01-30
6
540 Views
Last Modified: 2013-01-30
excel 2010 vba...

I need a function to activate during the Change event for a listbox.
I passing variable for the value to load an image will be in column(0) in the listbox.

What I need:

When a user scrolls in the listbox  a new image is displayed depending on the value in Column(0) in the listbox.

The path for the images file are in:

C:\MyPics\

trying to get this to work..

Dim Gsku As String
    Dim fPath As String
     
     'selects the range to look for a name.  You have to have a range
     'named  myName set up on column A.  Go to insert-name-define to
     'see how this one is set up.
    Gsku = ListBox1.Column(0)
        On Error Resume Next
        If Gsku Is Nothing Then
            Image1.Picture = LoadPicture(fPath & "NOTAVAIL.JPG")
        Else
                'Look in the directory where this workbook is located.
                fPath = "C:\MyPics"
                On Error Resume Next
                 'If a matching picture is found then display it.
                Image1.Picture = LoadPicture(fPath & Gsku & "_AS01.jpg")
                 'If No picture found then display the default picture.
                If Err = 0 Then Exit Sub
                Image1.Picture = LoadPicture(fPath & "nopic.gif")
         
        End If
0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 34

Accepted Solution

by:
Norie earned 500 total points
ID: 38837069
Does the code you posted not work?

One thing I can seet that might cause problems is the missing end \ from fPath.

Try adding it.
fPath = "C:\MyPics\"

Open in new window

0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 38837123
aaah ...Crazy  Thanks
0
 
LVL 3

Author Comment

by:fordraiders
ID: 38837226
during the change event I want to clear the pic for each change ?

this: Image1.Picture = Null

or this: Image1.Picture = "" 

is not working...
Sorry to ask again.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 34

Expert Comment

by:Norie
ID: 38837236
The 2nd code should work.

Are you getting an error?
0
 
LVL 3

Author Comment

by:fordraiders
ID: 38837430
yes
0
 
LVL 3

Author Comment

by:fordraiders
ID: 38837434
nm , its workin correctly...
my bad..
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question