Enlazar item de listbox a image1 (vba excel)

Grandísima ayuda con todas las dudas que nos surgen, a mi y a un montón de foreros.

MUCHAS GRACIAS!.

Siguiendo con mi proyecyo.

En el frm_articulos_buscar. Al hacer la búsqueda en el textbox, me sale en el listbox los resultados. Necesito que al señalizar un item del lilstbox en el image1 me salga la imagen correspondiente al articulo que he seleccionado.

1 Respuesta

Respuesta
1

Te anexo todo el código para el form buscar

Dim h1
'
Private Sub cmb_eliminar_Click()
    If txt_buscar.Value = "" Then
        MsgBox "Escribe un dato a buscar", vbInformation, "JJ VIDEOJUEGOS"
        Exit Sub
    End If
    If ListBox1.ListIndex = -1 Then
        MsgBox "Selecciona un artículo", vbInformation, "JJ VIDEOJUEGOS"
        Exit Sub
    End If
    fila = ListBox1.List(ListBox1.ListIndex, 4)
    If (MsgBox("¿Se eliminará el artículo seleccionado?", vbCritical + vbYesNo, " JJ VIDEOJUEGOS") = vbYes) Then
        h1.Rows(fila).Delete
        MsgBox "Artículo eliminado", vbInformation, "JJ VIDEOJUEGOS"
    Else
        Cancel = 1
    End If
    'Call cmb_buscar_Click
    '
    txt_buscar = ""
    ListBox1.Clear
End Sub
Private Sub cmb_volver_Click()
Unload Me
frm_articulos.Show
End Sub
Private Sub cmb_buscar_Click()
'Por.Dante Amor
    ListBox1.Clear
    If txt_buscar.Value = "" Then
        MsgBox "Escribe un dato a buscar", vbInformation, "JJ VIDEOJUEGOS"
        Exit Sub
    End If
    '
    Set r = h1.Columns("B")
    Set b = r.Find(txt_buscar, LookAt:=xlPart)
    If Not b Is Nothing Then
        celda = b.Address
        Do
            'detalle
            ListBox1. AddItem h1. Cells(b.Row, "A")
            ListBox1. List(ListBox1.ListCount - 1, 1) = h1. Cells(b.Row, "B")
            ListBox1. List(ListBox1.ListCount - 1, 2) = h1. Cells(b.Row, "C")
            ListBox1. List(ListBox1.ListCount - 1, 3) = h1. Cells(b.Row, "D")
            ListBox1. List(ListBox1.ListCount - 1, 4) = h1. Cells(b.Row, "E")
            ListBox1.List(ListBox1.ListCount - 1, 5) = b.Row
            Set b = r.FindNext(b)
        Loop While Not b Is Nothing And b.Address <> celda
    End If
End Sub
Private Sub cmb_modificar_Click()
    If txt_buscar.Value = "" Then
        MsgBox "Escribe un dato a buscar", vbInformation, "JJ VIDEOJUEGOS"
        Exit Sub
    End If
    'Por.Dante Amor
    If ListBox1.ListIndex = -1 Then
        MsgBox "Selecciona un artículo", vbInformation, "JJ VIDEOJUEGOS"
        Exit Sub
    End If
    Unload Me
    With frm_articulos_modificar
        .fila = ListBox1.List(ListBox1.ListIndex, 4)
        .Show
    End With
    '
    txt_buscar = ""
    ListBox1.Clear
End Sub
Private Sub ListBox1_Click()
'Por.Dante Amor
    ruta = ThisWorkbook.Path & "\Imagenes\"
    arch = ListBox1.List(ListBox1.ListIndex, 0) & ".jpg"
    If Dir(ruta & arch) <> "" Then
        img_articulos.Picture = LoadPicture(ruta & arch)
        img_articulos.PictureSizeMode = fmPictureSizeModeStretch
    Else
        If Dir(ruta & "ART14350000.jpg") <> "" Then
            img_articulos.Picture = LoadPicture(ruta & "ART14350000.jpg")
            img_articulos.PictureSizeMode = fmPictureSizeModeStretch
        End If
    End If
End Sub
Private Sub txt_buscar_Change()
    If txt_buscar.Value = "" Then
        ListBox1.Clear
        cmb_modificar.Enabled = False
        cmb_eliminar.Enabled = False
    Else
      cmb_modificar.Enabled = True
        cmb_eliminar.Enabled = True
        Exit Sub
    End If
End Sub
'
Private Sub UserForm_activate()
    Set h1 = Sheets("ARTICULOS")
    Sheets(2).Select
    Range("A2").Select
    txt_buscar.SetFocus
    cmb_modificar.Enabled = False
    cmb_eliminar.Enabled = False
End Sub

.

'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

.

Avísame cualquier duda

.

Gracias crack.

Hay un problema. Si borro mi código y pego el que tu me has puesto me da error

Pero si solo copio el código de listbox1_click, funciona perfecto.

¿Qué puede suceder?

El código que pusiste en la imagen no corresponde al código que yo te envié.

El form que yo modifiqué es el frm_articulos_buscar

Y el que tú pusiste en la imagen es el frm_articulos_modificar, ese form yo no lo he modificado.

¡Gracias!

Si, ese código lo coloque en el frm_articulos_buscar y el fallo me lo da en el frm_articulos_modificar.

Los frm funcionan de esta forma:

Busco un articulo, lo selecciono en el listbox y pulso el botón modificar y automáticamente me pasa los datos del articulo al frm_articulos_modificar.

Es ahí cuando me da el fallo. Pero si copio el código del listbox_click funciona perfecto.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas