Consulting

Results 1 to 4 of 4

Thread: Picture, changes with list selection

  1. #1
    VBAX Regular MUSASHI's Avatar
    Joined
    Oct 2004
    Location
    Corpus Christi, Texas (Very South)
    Posts
    44

    Picture, changes with list selection

    I have an employee list, named range "emplist". To view an employee I call a userform, it has a list box with various employee names....when I select employee I get the caption data, as well as a frame for a pic....I cant get the pic to show up...I been messing with this for a over an hour...shrugs

    what the heck am I doing wrong...big things first, then little things..hah

    Private Sub ListBox1_Click()
        Dim EmpFound As Range
        With Range("EmpList")
            Set EmpFound = .Find(ListBox1.Value)
            If EmpFound Is Nothing Then
                Label1.Caption = ""
            Else
                With EmpFound
                    Label1.Caption = "LastName: " & .Value & vbLf & _
                                    "FirstName: " & .Offset(, 1).Value & vbLf & _
                                    "Position: " & .Offset(, 2).Value & vbLf & _
                                    "Hired: " & .Offset(, 11).Value & vbLf & _
                                    "DOB: " & .Offset(, 9).Value & vbLf & _
                                    "SS#: " & .Offset(, 10).Value & vbLf & _
                                    "Employee#: " & .Offset(, 13).Value & vbLf & _
                                    "Phone: " & .Offset(, 7).Value
                    On Error Resume Next
                    Img_Employee.Picture = LoadPicture _
                        ("C:\Documents and Settings\Dunlap\excelprojects\" & EmpFound & ".bmp")
                    On Error GoTo 0
                End With
            End If
        End With
    End Sub
    the basic code came form Mr.Excel file...I added additional list items etc.

    Thx!

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi,

    This is what I use on a userform of mine ...

    Private Sub ComboBox1_Change() 'Change the combobox picture
        Dim fPath As String
        fPath = ThisWorkbook.path & "\"
        On Error Resume Next
        Img_loc.Picture = LoadPicture(fPath & ComboBox1.Value & ".jpg")
        If Err = 0 Then Exit Sub
        Img_loc.Picture = LoadPicture(fPath & "helpicon.jpg")
    End Sub

    Img_Loc is the name of the Picture box. As you can see, it's for a ComboBox, but you shouldn't have any trouble transferring it to a ListBox ...

    The 'helpicon.jpg' is a picture I have saved to the same directory (which this is defaulted to for all other pics) for those that don't match.

  3. #3
    VBAX Regular MUSASHI's Avatar
    Joined
    Oct 2004
    Location
    Corpus Christi, Texas (Very South)
    Posts
    44
    Thanks Fire!

    I'll give it a try, you and DRJ stick with me, I will get better!!! (I hope..heheh)

    Thx a lot, appreciate the time/help.




    Worked, after a little hammer....err I mean massaging..

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Well we will stick with you if you stick with us. LOL!

    Hope that helped. Post back if necessary. Take care.

Posting Permissions

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