I have a ListView control which is being loaded on form load procedure. I also provide a command button on the form whose purpose is to refresh the ListView control. This refresh button calls on the same code which is used to load the ListView on form load.
The ListView loads beautifully on form load but not when the refresh button is used (which as I said before calls on the same code which was used in form load?). When the refresh button is clicked it adds a bunch of blank lines at the top of the ListView control and then only some of the actual data below.
I did a Ctrl+Break and walked through the code. The code formats the grid as it should and begins looping through a recordset adding items to the ListView. After it gets through the tenth record, instead of adding the next record, it adds a blank line at the top of the ListView? Not sure why it is doing this. The recordset shows that data is there. It goes through the loop as though it is adding the data but then a blank row is added at the top. It does this for the remaining records.
Here is the code being called on both form load and refresh click event:
Private Sub LoadListView()
'Clear listview.
ListView1.ListItems.Clear
ListView1.ColumnHeaders.Clear
'Format ListView.
With ListView1
With .ColumnHeaders
.Add , "CompID", "CompID", 0, lvwColumnLeft
.Add , "Type", "Type", 650, lvwColumnLeft
.Add , "Vehicle", "Vehicle", 700, lvwColumnCenter
.Add , "Issuer", "Issuer", 3240, lvwColumnLeft
.Add , "Facility", "Facility", 1400, lvwColumnLeft
.Add , "Amount", "$ Amount", 1300, lvwColumnRight
.Add , "Price", "Price", 900, lvwColumnRight
.Add , "Analyst", "Analyst", 800, lvwColumnCenter
.Add , "Time", "Response Time", 2100, lvwColumnLeft
.Add , "TimeVal", "TimeVal", 0, lvwColumnLeft
End With
.View = lvwReport
' Open a recordset
MySQL = "SELECT tblCompRQST.Comp_id, [tblCompRQST]![deal-code] AS Vehicle, tblCompRQST.custom, " & _
"tblCompRQST.borrow_nbr, tblCompRQST.WU_id, tblCompRQST.WU_FacID, " & _
"IIf(IsNull([tblCompRQST]![custom]),UCase([tblWriteUp]![WU_Borrower]), " & _
"[Pilfile]![borrow_name]) AS Issuer, IIf(IsNull([tblCompRQST]![custom]), " & _
"[tblCapStruct]![FacDesc],[Pilfile]![loan_desc]) AS Facility, tblCompRQST.Analyst, " & _
"tblCompRQST.Price, tblCompRQST.Amount, tblCompRQST.Response_time, tblCompRQST.Status, " & _
"tblCompRQST.Type, tblCompRQST.Settled " & _
"FROM (((((tblCompRQST LEFT JOIN tblWriteUp ON tblCompRQST.WU_id = tblWriteUp.WU_id) " & _
"LEFT JOIN tblCapStruct ON tblCompRQST.WU_FacID = tblCapStruct.WU_FacID) LEFT JOIN " & _
"Pilfile ON tblCompRQST.borrow_nbr = Pilfile.borrow_nbr) LEFT JOIN tblMoodyCLOindustry ON " & _
"Pilfile.moody_code = tblMoodyCLOindustry.SSBIndustryCode) LEFT JOIN tblSPCLOindustry ON " & _
"Pilfile.sp_code = tblSPCLOindustry.SPIndustryCode) LEFT JOIN tblFIndustry ON " & _
"tblCompRQST.FIndustryCode = tblFIndustry.FIndustryCode " & _
"GROUP BY tblCompRQST.Comp_id, [tblCompRQST]![deal-code], tblCompRQST.custom, " & _
"tblCompRQST.borrow_nbr, tblCompRQST.WU_id, tblCompRQST.WU_FacID, " & _
"IIf(IsNull([tblCompRQST]![custom]),UCase([tblWriteUp]![WU_Borrower]), " & _
"[Pilfile]![borrow_name]), IIf(IsNull([tblCompRQST]![custom]),[tblCapStruct]![FacDesc], " & _
"[Pilfile]![loan_desc]), tblCompRQST.Analyst, tblCompRQST.Price, tblCompRQST.Amount, " & _
"tblCompRQST.Response_time, tblCompRQST.Status, tblCompRQST.Type, tblCompRQST.Settled " & _
"Having (((tblCompRQST.Status)='ACCEPTED') AND ((tblCompRQST.Settled)=No));"
Set MyDb = OpenDatabase(RDSDATA_PATH & "rdstables.mdb"
Set MySet = MyDb.OpenRecordset(MySQL)
'Execute code if MySet is not empty.
If MySet.RecordCount <> 0 Then
'Moves to the first record in the recordset.
MySet.MoveFirst
' Use values from recordset to populate listview control
'****THIS IS WHERE PROBLEM OCCURS****
For I = 1 To MySet.RecordCount
.ListItems.Add I, , MySet.Fields("Comp_id"
With .ListItems(I).ListSubItems
.Add , , MySet.Fields("Type"
.Add , , MySet.Fields("Vehicle"
.Add , , MySet.Fields("Issuer"
.Add , , MySet.Fields("Facility"
.Add , , Format(MySet.Fields("Amount"
, "#,###.00"
.Add , , Format(MySet.Fields("Price"
, "###.0000"
.Add , , MySet.Fields("Analyst"
.Add , , MySet.Fields("Response_time"
.Add , , Format(MySet.Fields("Response_time"
, "yyyymmddhhmmss"
End With
MySet.MoveNext
Next I
'***********************************
End If
End With
MySet.Close
MyDb.Close
Set MySet = Nothing
Set MyDb = Nothing
'Set Sort Optiot button to Ascending (A-Z).
Option2(0).Value = True
lblSelectA.Caption = "0"
End Sub
The ListView loads beautifully on form load but not when the refresh button is used (which as I said before calls on the same code which was used in form load?). When the refresh button is clicked it adds a bunch of blank lines at the top of the ListView control and then only some of the actual data below.
I did a Ctrl+Break and walked through the code. The code formats the grid as it should and begins looping through a recordset adding items to the ListView. After it gets through the tenth record, instead of adding the next record, it adds a blank line at the top of the ListView? Not sure why it is doing this. The recordset shows that data is there. It goes through the loop as though it is adding the data but then a blank row is added at the top. It does this for the remaining records.
Here is the code being called on both form load and refresh click event:
Private Sub LoadListView()
'Clear listview.
ListView1.ListItems.Clear
ListView1.ColumnHeaders.Clear
'Format ListView.
With ListView1
With .ColumnHeaders
.Add , "CompID", "CompID", 0, lvwColumnLeft
.Add , "Type", "Type", 650, lvwColumnLeft
.Add , "Vehicle", "Vehicle", 700, lvwColumnCenter
.Add , "Issuer", "Issuer", 3240, lvwColumnLeft
.Add , "Facility", "Facility", 1400, lvwColumnLeft
.Add , "Amount", "$ Amount", 1300, lvwColumnRight
.Add , "Price", "Price", 900, lvwColumnRight
.Add , "Analyst", "Analyst", 800, lvwColumnCenter
.Add , "Time", "Response Time", 2100, lvwColumnLeft
.Add , "TimeVal", "TimeVal", 0, lvwColumnLeft
End With
.View = lvwReport
' Open a recordset
MySQL = "SELECT tblCompRQST.Comp_id, [tblCompRQST]![deal-code] AS Vehicle, tblCompRQST.custom, " & _
"tblCompRQST.borrow_nbr, tblCompRQST.WU_id, tblCompRQST.WU_FacID, " & _
"IIf(IsNull([tblCompRQST]![custom]),UCase([tblWriteUp]![WU_Borrower]), " & _
"[Pilfile]![borrow_name]) AS Issuer, IIf(IsNull([tblCompRQST]![custom]), " & _
"[tblCapStruct]![FacDesc],[Pilfile]![loan_desc]) AS Facility, tblCompRQST.Analyst, " & _
"tblCompRQST.Price, tblCompRQST.Amount, tblCompRQST.Response_time, tblCompRQST.Status, " & _
"tblCompRQST.Type, tblCompRQST.Settled " & _
"FROM (((((tblCompRQST LEFT JOIN tblWriteUp ON tblCompRQST.WU_id = tblWriteUp.WU_id) " & _
"LEFT JOIN tblCapStruct ON tblCompRQST.WU_FacID = tblCapStruct.WU_FacID) LEFT JOIN " & _
"Pilfile ON tblCompRQST.borrow_nbr = Pilfile.borrow_nbr) LEFT JOIN tblMoodyCLOindustry ON " & _
"Pilfile.moody_code = tblMoodyCLOindustry.SSBIndustryCode) LEFT JOIN tblSPCLOindustry ON " & _
"Pilfile.sp_code = tblSPCLOindustry.SPIndustryCode) LEFT JOIN tblFIndustry ON " & _
"tblCompRQST.FIndustryCode = tblFIndustry.FIndustryCode " & _
"GROUP BY tblCompRQST.Comp_id, [tblCompRQST]![deal-code], tblCompRQST.custom, " & _
"tblCompRQST.borrow_nbr, tblCompRQST.WU_id, tblCompRQST.WU_FacID, " & _
"IIf(IsNull([tblCompRQST]![custom]),UCase([tblWriteUp]![WU_Borrower]), " & _
"[Pilfile]![borrow_name]), IIf(IsNull([tblCompRQST]![custom]),[tblCapStruct]![FacDesc], " & _
"[Pilfile]![loan_desc]), tblCompRQST.Analyst, tblCompRQST.Price, tblCompRQST.Amount, " & _
"tblCompRQST.Response_time, tblCompRQST.Status, tblCompRQST.Type, tblCompRQST.Settled " & _
"Having (((tblCompRQST.Status)='ACCEPTED') AND ((tblCompRQST.Settled)=No));"
Set MyDb = OpenDatabase(RDSDATA_PATH & "rdstables.mdb"
Set MySet = MyDb.OpenRecordset(MySQL)
'Execute code if MySet is not empty.
If MySet.RecordCount <> 0 Then
'Moves to the first record in the recordset.
MySet.MoveFirst
' Use values from recordset to populate listview control
'****THIS IS WHERE PROBLEM OCCURS****
For I = 1 To MySet.RecordCount
.ListItems.Add I, , MySet.Fields("Comp_id"
With .ListItems(I).ListSubItems
.Add , , MySet.Fields("Type"
.Add , , MySet.Fields("Vehicle"
.Add , , MySet.Fields("Issuer"
.Add , , MySet.Fields("Facility"
.Add , , Format(MySet.Fields("Amount"
.Add , , Format(MySet.Fields("Price"
.Add , , MySet.Fields("Analyst"
.Add , , MySet.Fields("Response_time"
.Add , , Format(MySet.Fields("Response_time"
End With
MySet.MoveNext
Next I
'***********************************
End If
End With
MySet.Close
MyDb.Close
Set MySet = Nothing
Set MyDb = Nothing
'Set Sort Optiot button to Ascending (A-Z).
Option2(0).Value = True
lblSelectA.Caption = "0"
End Sub