p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   Beginning VB 6 (http://p2p.wrox.com/beginning-vb-6-75/)
-   -   Access Recordset to listview (http://p2p.wrox.com/beginning-vb-6/86453-access-recordset-listview.html)

klnp_mysore January 25th, 2012 01:07 AM

Access Recordset to listview
 
Hi,
I am getting an error while loading access table to listview, the error message is "Invalid Property Value"
Code:

Private Sub Form_Load()
Call addforqry("Select * from ltplan", ListView1)
End Sub

Public Sub addforqry(qry As String, lv As Control)
Dim i As Integer, cnt As Integer
Dim rd As New ADODB.Recordset
Dim cn As New ADODB.Connection
cn.Open "KEC1"
'Dim qry As String
'qry = "Select * from ltplan"
Set rd = cn.Execute(qry)
lv.ColumnHeaders.Clear
lv.ListItems.Clear
For i = 0 To rd.Fields.Count - 1
    lv.ColumnHeaders.Add , , rd.Fields(i).Name
Next
cnt = 1
If rd.BOF = False Then
Do Until rd.EOF
    lv.ListItems.Add cnt, , cnt
    For i = 0 To rd.Fields.Count - 1
        temp = rd(i)
        lv.ListItems(cnt).SubItems(i) = temp
        Next
        cnt = cnt + 1
        rd.MoveNext
        Loop
End If

Please help
Regards


All times are GMT -4. The time now is 06:12 PM.

Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.