Hi, this code that I have below is saved in a module. And this line: Call loadProduct_ListView(Me, ListView1) is in a userform that calls the code below. Every time I run the code I get this error:
If I change the code to only work for one ListView then it works, but I want it to work for multiple ListViews, otherwise I would have to rewrite the code for each ListView. Is there a way that this can be done? I have a feeling that something may be wrong with this line: Sub loadProduct_ListView(uf As UserForm, lv1 As Object). Specifically the lv1 As Object, but I'm not sure. Thank you for any help.
If I change the code to only work for one ListView then it works, but I want it to work for multiple ListViews, otherwise I would have to rewrite the code for each ListView. Is there a way that this can be done? I have a feeling that something may be wrong with this line: Sub loadProduct_ListView(uf As UserForm, lv1 As Object). Specifically the lv1 As Object, but I'm not sure. Thank you for any help.
VBA Code:
Sub loadProduct_ListView(uf As UserForm, lv1 As Object)
' Dim xSheet As String: xSheet = Sheet1.Name '("DB_Product")
' Dim Tabs As Worksheet: Set Tabs = ThisWorkbook.Worksheets(xSheet)
Dim sRow As Integer: sRow = 7
Dim LRow As Integer: LRow = Range("a" & Rows.Count).End(xlUp).Row
Dim VlrCel As String
Dim CntRegs As Integer: CntRegs = 0
' Dim VlrPesq As String: VlrPesq = Me.TextBox5.Text
Dim lv, oMask
Set WbDb = Workbooks("TimeSheet-Calculator_TrumpExcelRevised-2021_v1.xlsm")
Set WbCd = ThisWorkbook
Set ShDb = WbDb.Sheets("Sheet1")
Application.ScreenUpdating = False
WbDb.Activate
ShDb.Activate
Range("A2").Select
If LRow < 0 Then
MsgBox "There is no data registered at the moment !", vbCritical
Exit Sub
End If
uf.lv1.ListItems.Clear
With ShDb
While .Cells(sRow, "e").Value <> Empty
' VlrCel = .Cells(sRow, "e").Value
' If InStr(1, UCase(VlrCel), UCase(VlrPesq), 1) Then
With uf
Set lv = .lv1.ListItems.Add(Text:=Format(Cells(sRow, "a"), oMask)) 'REC. ID
lv.ListSubItems.Add Text:=Format(Cells(sRow, "b"), "h:mm") 'VENDOR
lv.ListSubItems.Add Text:=Format(Cells(sRow, "c"), oMask) 'STOR SKU#
lv.ListSubItems.Add Text:=Format(Cells(sRow, "d"), "$ #,##0") 'ITEM NAME
lv.ListSubItems.Add Text:=Format(Cells(sRow, "e"), "$ #,##0") 'DISCRIPTION
lv.ListSubItems.Add Text:=Format(Cells(sRow, "f"), oMask) 'UNIT
lv.ListSubItems.Add Text:=Format(Cells(sRow, "g"), oMask) 'QTY
lv.ListSubItems.Add Text:=Format(Cells(sRow, "h"), oMask) 'UNIT PRICE
lv.ListSubItems.Add Text:=Format(Cells(sRow, "i"), oMask) 'TRADE OF WORK
lv.ListSubItems.Add Text:=Format(Cells(sRow, "j"), oMask) 'ITEM TYPE
lv.ListSubItems.Add Text:=Format(Cells(sRow, "k"), oMask) 'TAX
lv.ListSubItems.Add Text:=Format(Cells(sRow, "l"), "mm") 'CITY
lv.ListSubItems.Add Text:=Format(Cells(sRow, "m"), "d") 'STATE
lv.ListSubItems.Add Text:=Format(Cells(sRow, "n"), "ddd") 'REC. DATE
lv.ListSubItems.Add Text:=Format(Cells(sRow, "o"), "h:mm") 'UPD DATE
lv.ListSubItems.Add Text:=Format(Cells(sRow, "p"), "h:mm") 'WEIGHT (lb)
lv.ListSubItems.Add Text:=Format(Cells(sRow, "q"), oMask) 'Produto
lv.ListSubItems.Add Text:=Format(Cells(sRow, "r"), oMask) 'IMAGES
lv.ListSubItems.Add Text:=Format(Cells(sRow, "s"), oMask) 'Produto
lv.ListSubItems.Add Text:=Format(Cells(sRow, "t"), oMask) 'IMAGES
' CntRegs = CntRegs + 1
' End If
sRow = sRow + 1
End With
Wend
Set lv = Nothing
End With
'=======================================================
Application.ScreenUpdating = True
' WbDb.Close
Set WbDb = Nothing
Set ShDb = Nothing
Set WbCd = Nothing
End Sub
Call loadProduct_ListView(Me, ListView1)