Solved

Load Image from Listbox Change Event

Posted on 2013-01-30
6
522 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
  • 4
  • 2
6 Comments
 
LVL 33

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 33

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now