Load ListView with Data

JarekM

Board Regular
Joined
Nov 13, 2018
Messages
86
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:
Microsoft Visual Basic for Applications - TimeSheet-Calculator_TrumpExcelRevised-2021_v1.xlsm ...png

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)
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
First of all, it is NOT good practice in VBA to use the underscore character in variable or procedure names. Typically the underscore is used in object event procedure names only. I don't know if that is causing the error but best if you don't use it as you are.

Now, the Call loadProduct_ListView line, is it in the UserForm code or in a separate Standard Module? Based on what you have shown, it should be in a Standard Module.

One other thought right now is that in the Sub loadProduct_ListView line, change the "lv1 as Object" to "lv1 as ListView". Object as a type may limit what properties and methods that are accessible.

Will need to have more info to say any more at this time.
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top