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 UFScheda Navigazione:
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
UFVisualizzaGiocatore.Show
End Sub
While, here below the code contained in UFVisualizzaGiocatore:
Private Sub UserForm_Initialize()
Dim rngID As Range
Dim X As String
Dim objPic As IPictureDisp
Dim shp As Shape
Dim pic As Shape
Dim Row As Long
Dim ImgRiga As String
Dim ImgCarica As Image
Me.Image1.BackColor = RGB(4, 34, 46)
Me.LblTitolo.BackColor = RGB(4, 34, 46)
Me.TxtVID = IDVisualizza
Worksheets(2).Activate
LastRow = Worksheets(2).Range("A" & Rows.Count).End(xlUp).Row
Set rngNome = Worksheets(2).Range("A2:A" & LastRow)
For Each rngID In rngNome
If rngID.Value = IDVisualizza Then
Row = rngID.Row
Me.TxtVNome.Value = rngID.Offset(, 1).Value
Me.TxtVCognome.Value = rngID.Offset(, 2).Value
Me.TxtVAnnoNascita.Value = rngID.Offset(, 3).Value
End If
ImgRiga = "Img" & Row & ".Picture"
ImgCarica = "UFImmagini." & ImgRiga
UFImmagini.Hide
Me.ImgVGiocatore.Picture = ImgCarica
Next rngID
End Sub
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?
Thanks,
A
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 UFScheda Navigazione:
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
UFVisualizzaGiocatore.Show
End Sub
While, here below the code contained in UFVisualizzaGiocatore:
Private Sub UserForm_Initialize()
Dim rngID As Range
Dim X As String
Dim objPic As IPictureDisp
Dim shp As Shape
Dim pic As Shape
Dim Row As Long
Dim ImgRiga As String
Dim ImgCarica As Image
Me.Image1.BackColor = RGB(4, 34, 46)
Me.LblTitolo.BackColor = RGB(4, 34, 46)
Me.TxtVID = IDVisualizza
Worksheets(2).Activate
LastRow = Worksheets(2).Range("A" & Rows.Count).End(xlUp).Row
Set rngNome = Worksheets(2).Range("A2:A" & LastRow)
For Each rngID In rngNome
If rngID.Value = IDVisualizza Then
Row = rngID.Row
Me.TxtVNome.Value = rngID.Offset(, 1).Value
Me.TxtVCognome.Value = rngID.Offset(, 2).Value
Me.TxtVAnnoNascita.Value = rngID.Offset(, 3).Value
End If
ImgRiga = "Img" & Row & ".Picture"
ImgCarica = "UFImmagini." & ImgRiga
UFImmagini.Hide
Me.ImgVGiocatore.Picture = ImgCarica
Next rngID
End Sub
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?
Thanks,
A