Kamis saya membenahi module pada project kelas terapi.Semula Project saya error pada modul listview , setelah saya benahi kemudian program saya bisa d run tanpa error.
Di bawah ini adalah coding yang sudah saya beenahi :
Public rs As New ADODB.Recordset
Public sqlstr As String
Public con As New ADODB.Connection
Option Explicit
Function koneksi(server As String, user As String, pass As String, database As String, con As ADODB.Connection) As Boolean
On Error GoTo pesan
If con.State = adStateOpen Then con.Close
con.Open "Provider=SQLNCLI10;Server =" & server & "; User =" & user & ";Password=" & pass & ";Database=" & database & ";Trusted_Connection=yes"
koneksi = True
Exit Function
pesan:
koneksi = False
MsgBox "Koneksi Gagal"
End Function
Function listview(Lv1 As listview, Query As String, con As ADODB.Connection)
Dim I As Integer
Dim s As Integer
Dim ilv As ListItem
Dim ch As ColumnHeader
Dim j As Integer
'rs.CursorLocation = adUseClient
Lv1.View = lvwReport
Set rs = con.Execute(Query)
Lv1.ColumnHeaders.Clear
For I = 0 To rs.Fields.Count - 1 'menentukan perulangan kolom header
Set ch = Lv1.ColumnHeaders.Add(, , rs.Fields(I).Name, 2000) 'menampilkan nama field pada table
Next I
'isi Data
Lv1.ListItems.Clear
Lv1.GridLines = True
While Not rs.EOF
For j = 0 To rs.Fields.Count - 1
If j = 0 Then
Set ilv = Lv1.ListItems.Add(, , rs.Fields(j))
Else
ilv.SubItems(j) = rs.Fields(j)
End If
Next j
rs.MoveNext
Wend
End Function
Tidak ada komentar:
Posting Komentar