+ Reply to Thread
Results 1 to 2 of 2

ListView odd behavior

Hybrid View

  1. #1
    Registered User
    Join Date
    01-29-2013
    Location
    texas
    MS-Off Ver
    Excel 2010
    Posts
    68

    ListView odd behavior

    Hi all,

    This code works fine the first time thru. I'm passing a month (m) to the sub.

    Sub AAViewFill(m)
        amtTotal = 0
        Dim lv_item As Integer 'no of the listview item
    
        lv_item = 1
        With frmView!ListView1
             'gives me headers at the top
            'frmView!ListView1.View = lvwReport
            .ListItems.Clear
             'defining the columnheaders
            With .ColumnHeaders
                .Clear
                .Add , , "", 0
                .Add , , "Rec#", 30
                .Add , , "Asset", 70
                .Add , , "Owner", 37
                .Add , , "Day Due", 40
                .Add , , "Paid", 33
                .Add , , "Amt. Due", 55
                '.Add , , "Basis", 55
            End With
            .HideColumnHeaders = False
            .Appearance = cc3D
            frmView!ListView1.ColumnHeaders(2).Alignment = lvwColumnRight
            frmView!ListView1.ColumnHeaders(4).Alignment = lvwColumnRight
            frmView!ListView1.ColumnHeaders(6).Alignment = lvwColumnCenter
            frmView!ListView1.ColumnHeaders(5).Alignment = lvwColumnCenter
            frmView!ListView1.ColumnHeaders(7).Alignment = lvwColumnCenter
            'ListView1.ColumnHeaders(8).Alignment = lvwColumnCenter
            .FullRowSelect = True
            For i = 3 To UBound(myNewArray)
                If Len(myNewArray(i, 15)) < 2 And Mid(myNewArray(i, 4), m, 1) <> "o" Then
                Stop
                'If Len(myNewArray(i, 15)) < 2 Then
                    .ListItems.Add , , myNewArray(i, 1)
                    .ListItems(lv_item).ForeColor = RGB(195, 0, 0)
                    .ListItems(lv_item).ListSubItems.Add , , myNewArray(i, 1)       'Record Number
                    .ListItems(lv_item).ListSubItems.Add , , myNewArray(i, 2)       'Asset Name
                    .ListItems(lv_item).ListSubItems.Add , , myNewArray(i, 3)       'Owner
                    .ListItems(lv_item).ListSubItems.Add , , Format(myNewArray(i, 5), "00")
                    .ListItems(lv_item).ListSubItems.Add , , "   "
                    
                    'Format(!Id, "0000")
                    .ListItems(lv_item).ListSubItems.Add , , Format(Format(myNewArray(i, 7), "###,##0.00"), "@@@@@@@@@@@@@")   'Amt.Due
                    'If Val(myNewArray(i, 13)) < 100 Then
                    '    .ListItems(lv_item).ListSubItems.Item(4).ForeColor = RGB(255, 0, 0)
                    'End If
                    '.ListItems(lv_item).ListSubItems.Add , , Format(Format(myNewArray(i, 12), "###,##0.00"), "@@@@@@@@@@@@@")   'YTD
                    '.ListItems(lv_item).ListSubItems.Add , , Format(Format(myNewArray(i, 13), "###,##0.00"), "@@@@@@@@@@@@@")   'Value
                    '.ListItems(lv_item).ListSubItems.Add , , Format(Format(myNewArray(i, 12), "###,##0.00"), "@@@@@@@@@@@@@")   'Basis
                    '.ListItems.Add , , Worksheets("Sheet1").Range("A" & pos)
                    '.ListItems(lv_item).ForeColor = RGB(0, 0, 0)
                    '.ListItems(lv_item).ListSubItems.Add , , Worksheets("Sheet1").Range("B" & pos)
                    '.ListItems(lv_item).ListSubItems.Add , , Worksheets("Sheet1").Range("C" & pos)
                    '.ListItems(lv_item).ListSubItems.Add , , Worksheets("Sheet1").Range("D" & pos)
                    lv_item = lv_item + 1
                    'pos = pos + 1
                    amtTotal = amtTotal + Val(myNewArray(i, 7))
                End If
             'Stop
            Next i
        End With
        frmView!ListView1.SortKey = 4
        frmView!ListView1.SortOrder = lvwAscending
        frmView!ListView1.Sorted = True
    
        'txtTotalYTD.Text = ytdTotal
        frmView!txtTotalYTD.Left = 225
        frmView!txtTotalYTD.value = Format(amtTotal, "###,###.00")
    End Sub
    The second time thru with a different month the list and headers are cleared and the first record is placed properly, but the second and subsequent records force the first record down the list and the others appear as blanks.

    I've used similar code with no problems, but this has me whipped.
    Any help appreciated

  2. #2
    Registered User
    Join Date
    01-29-2013
    Location
    texas
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: ListView odd behavior

    Found it.
    Sort must be set to false before each run thru.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1