To add all records of a table to a listview control just by specifying the name of the table
To add all records of a table to a listview control just by specifying the name of the table
API Declarations
Public table As String
Public cnn As New ADODB.Connection
Public rs1 As New ADODB.Recordset
Rate To add all records of a table to a listview control just by specifying the name of the table
(1(1 Vote))
'Important:Name the listview as lv U may have any no of forms with listview 'control but name them as lv(listview name property)
Public Sub connect()
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source= NAME OF U R DATABASE WITH PATH SPECIFIED"
End Sub
Public Sub check(rs As ADODB.Recordset)
If rs.State = 1 Then rs.Close
End Sub
Public Sub Lview(frm As Form, table As Variant)
Dim X As Integer
Dim i As Integer
Dim lst As ListItem
For i = 1 To frm.lv.ColumnHeaders.Count
frm.lv.ColumnHeaders.Remove (1)
Next i
check rs1
rs1.Open "select * from " & table, cnn, adOpenDynamic, adLockOptimistic
frm.lv.ListItems.clear
For X = 0 To rs1.Fields.Count - 1
frm.lv.ColumnHeaders.Add , , rs1.Fields(X).Name
Next X
While Not rs1.EOF
Set lst = frm.lv.ListItems.Add (, , rs1(0))
For X = 1 To rs1.Fields.Count - 1
If Not IsNull(rs1(X)) Then lst.SubItems(X) = rs1(X)
Next X
rs1.MoveNext
Wend
End Sub
'put this code in form load
Private Sub Form_Load()
connect
End Sub
'Where ever and when ever u need to fill ur listview named lv with the records 'of u r table connected with database cnn Just call this procedure
' Lview formname,tablename
' Ex: Lview me,"Employee" (current form &table name is employee)
To add all records of a table to a listview control just by specifying the name of the table Comments
No comments yet — be the first to post one!
Post a Comment