Results 1 to 2 of 2

Thread: Image Control in Userform

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2018

    Image Control in Userform

    Hello everybody,
    I'm building a quite complex Excel model - complex at least for me.

    Objects involved are basically 3:
    - Worksheet containing data;
    - Userform1 (UFSchedaNavigazione) where I have the list of data contained in Worksheet;
    - Userform2 (UFImmagini) where I have a set of pictures whose names contain the row of the related data in Worksheet;
    - Userform 3 (UFVisualizzaGiocatore) where I want to display after selection in UFSchedaNavigazione data contained in Worksheet plus image from Userform (UFImmagini).

    But, when I doubleclick on the item in listbox of UFSchedaNavigazione, I receive the message "Run-time error 91: Object Variable or With Block variable not set".

    Here below the code contained in Userform UFSchedaNavigazione:

    Private Sub LstBoxRicercaGiocatore_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    For i = 0 To LstBoxRicercaGiocatore.ListCount - 1
            If LstBoxRicercaGiocatore.Selected(i) = True Then
    'set the listbox column
                ID = LstBoxRicercaGiocatore.List(i, 0)
                IDVisualizza = ID
            End If
    Next i
    End Sub
    While, here below the code contained in UFVisualizzaGiocatore:

    Private Sub UserForm_Initialize()
    Dim rngID As Long
    Dim X As Variant
    Dim objPic As IPictureDisp
    Dim shp As Shape
    Dim pic As Shape
    Dim Row As Long
    Dim ImgRiga As String
    Dim ImgCarica As Object
    Me.Image1.BackColor = RGB(4, 34, 46)
    Me.LblTitolo.BackColor = RGB(4, 34, 46)
    Me.TxtVID = IDVisualizza
    rngID = 2
    X = Worksheets(2).Cells(rngID, 1).Value
    Do While Not X = IDVisualizza
    rngID = rngID + 1
    X = Worksheets(2).Cells(rngID, 1).Value
    UltimaRiga = rngID
    Me.TxtVID = Worksheets(2).Cells(rngID, 1).Value
    ImgRiga = "Img" & rngID & ".Picture"
    ImgCarica = "UFImmagini." & ImgRiga
    Me.ImgVGiocatore.Picture = ImgCarica
    As said, when I doubleclick on item of the Listbox contained in UFSchedaNavigazione, I get the error mesage. Any clue how I can sort this out (even with other workarounds)?


  2. #2
    Join Date
    Dec 2004

    Re: Image Control in Userform

    this error is specific, but as you have not specified which line the error occurs, as most of the code refers to the listbox object that has been clicked, i doubt that it is causing the error
    leaves me to guess that the error occurs on the line IDVisualizza = ID, assuming that IDVisualizza is an object of some sort, maybe on some other userform to the one where the code is, possibly UFVisualizzaGiocatore, if so try
    UFVisualizzaGiocatore.IDVisualizza = ID

    without seeing your workbook, to help further,
    we would need to know what controls or other objects are contained in which userforn or worksheet
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed

Posting Permissions

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


Click Here to Expand Forum to Full Width