Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying records in a ListView 1

Status
Not open for further replies.

HaworthBantam

Programmer
Jan 31, 2002
132
GB
I have a ListView box on a form called lvwPostings.

On opening the form, code is executed that creates an Adodc recordset. The records contained within the recordset then need to be displayed within the ListView box. I am, however, having problems displaying the records.

The code so far is.....

Private Sub Form_Load()

Dim strPostingsSQL As String

strPostingsSQL ="SELECT * FROM tblPostings WHERE RemRef = " & lngRecordID & " AND Type =" & Chr(34) & strTaxType & Chr(34)

Adodc2.ConnectionString = strConnectionString
Adodc2.CommandType = adCmdText
Adodc2.RecordSource = strPostingsSQL
Adodc2.Refresh

With lvwPosings
.View = lvwReport
.FullRowSelect = True
.ColumnHeaders.Add,,"RemRef"
.ColumnHeaders(1).Width = 1000
.ColumnHeaders.Add,,"Tax"
.ColumnHeaders(2).Width = 1000
.ColumnHeaders.Add,,"NIC"
.ColumnHeaders(3).Width = 1000
End With

The code up to this point works. I know that through the use of message boxes and stepping through.

I'm now unsure how to populate the ListView box from the Adodc recordset. I do know that I'll need to cycle through the recordset and add each record one at a time, but the code I've written does not work, and I don't wish to embarrass myself by displaying it here !

I know I'm missing something numpty but any help getting me back on track would be a great help.

Thanks.
 
Here's a snippet from anm old project which may get you started:

Me.lvwParts.ListItems.Clear
Dim itmx As ListItem
Dim lngCount as Long
With rst
Do While Not .EOF
Set itmx = lvwParts.ListItems.Add(lngCount, , .Fields(1))
itmx.SubItems(1) = .Fields(0)
itmx.SubItems(2) = .Fields(2)
.MoveNext
lngCount = lngCount + 1
Loop
rst.Close
Set rst = Nothing
End With
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
I used a variation of your code but received error "35600 Index out of bounds".

However, when I trapped the error and resumed next it worked fine.

I can live with trapping the error so thanks a lot mate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top