untuk koneksi kita siapkan module
isi dengan coding :
Public MyConn As New MYSQL_CONNECTION
dan pada form akun ini kita isi coding untuk konek ke sql
Private Sub Form_Activate()
Dim sql As String
Dim rs As MYSQL_RS
sql = "SELECT * FROM akun"
Set rs = MyConn.Execute(sql)
If MyConn.Error.Number <> 0 Then MsgBox MyConn.Error.Description
Do While Not rs.EOF
Set lv = lvw.ListItems.Add(, , rs.Fields(0).Value)
lv.ListSubItems.Add , , rs.Fields(1).Value
lv.ListSubItems.Add , , rs.Fields(2).Value
lv.ListSubItems.Add , , rs.Fields(3).Value
lv.ListSubItems.Add , , rs.Fields(4).Value
lv.ListSubItems.Add , , rs.Fields(5).Value
rs.MoveNext
Loop
End Sub
------------------------------------------------------
Private Sub Form_Load()
MyConn.OpenConnection "localhost", "root", "", "siapershdagang"
If MyConn.Error.Number <> 0 Then
MsgBox MyConn.Error.Description
End If
End Sub
'karena database kita siapershdagang maka kita isi siapershdagang
-------------------------------------------------------
Coding Input
Private Sub CmdInput_Click()
Dim sql As String
Dim rs As MYSQL_RS
sql = "INSERT into akun (kodeakun,namaakun,saldonormal,jenisrekening,kodeparent,kelompokrekening)values ('" & Text1.Text & "','" & Text2.Text & "','" & IIf(OptD.Value = True, "D", "K") & "','" & Combo2.Text & "','" & Text3.Text & "','" & Combo3.Text & "') "
MyConn.Execute sql
If MyConn.Error.Number <> 0 Then MsgBox MyConn.Error.Description + " " + sql
lvw.ListItems.Clear
sql = "SELECT * FROM akun"
Set rs = MyConn.Execute(sql)
If MyConn.Error.Number <> 0 Then MsgBox MyConn.Error.Description
Do While Not rs.EOF
Set lv = lvw.ListItems.Add(, , rs.Fields(0).Value)
lv.ListSubItems.Add , , rs.Fields(1).Value
lv.ListSubItems.Add , , rs.Fields(2).Value
lv.ListSubItems.Add , , rs.Fields(3).Value
lv.ListSubItems.Add , , rs.Fields(4).Value
lv.ListSubItems.Add , , rs.Fields(5).Value
rs.MoveNext
Loop
End Sub
--------------------------------------------------
Coding Edit
Private Sub CmdEdit_Click()
Dim sql As String
Dim rs As MYSQL_RS
sql = "update akun set namaakun='" & Text2.Text & "',saldonormal='" & IIf(OptD.Value = True, "D", "K") & "',jenisrekening='" & Combo2.Text & "',kodeparent='" & Text3.Text & "',kelompokrekening='" & Combo3.Text & "' where kodeakun='" & Text1.Text & "' "
frmAkun.Tag = "Edit"
frmAkun.Text1.Text = lvw.SelectedItem.Text
frmAkun.Text2.Text = lvw.SelectedItem.SubItems(1)
If lvw.SelectedItem.SubItems(2) = "D" Then
frmAkun.OptD.Value = True
Else
frmAkun.OptK.Value = True
End If
If lvw.SelectedItem.SubItems(3) = "real" Then
frmAkun.Combo2.ListIndex = 0
ElseIf lvw.SelectedItem.SubItems(3) = "nominal" Then
frmAkun.Combo2.ListIndex = 1
End If
frmAkun.Text3.Text = lvw.SelectedItem.SubItems(4)
If lvw.SelectedItem.SubItems(5) = "aktiva" Then
frmAkun.Combo3.ListIndex = 0
ElseIf lvw.SelectedItem.SubItems(5) = "utang" Then
frmAkun.Combo3.ListIndex = 1
ElseIf lvw.SelectedItem.SubItems(5) = "modal" Then
frmAkun.Combo3.ListIndex = 2
ElseIf lvw.SelectedItem.SubItems(5) = "pendapatan" Then
frmAkun.Combo3.ListIndex = 3
ElseIf lvw.SelectedItem.SubItems(5) = "biaya" Then
frmAkun.Combo3.ListIndex = 4
End If
MyConn.Execute sql
If MyConn.Error.Number <> 0 Then MsgBox MyConn.Error.Description + " " + sql
lvw.ListItems.Clear
sql = "SELECT * FROM akun"
Set rs = MyConn.Execute(sql)
If MyConn.Error.Number <> 0 Then MsgBox MyConn.Error.Description
Do While Not rs.EOF
Set lv = lvw.ListItems.Add(, , rs.Fields(0).Value)
lv.ListSubItems.Add , , rs.Fields(1).Value
lv.ListSubItems.Add , , rs.Fields(2).Value
lv.ListSubItems.Add , , rs.Fields(3).Value
lv.ListSubItems.Add , , rs.Fields(4).Value
lv.ListSubItems.Add , , rs.Fields(5).Value
rs.MoveNext
Loop
End Sub
-----------------------------------------------
Coding Hapus
Private Sub CmdHapus_Click()
Dim sql As String
If MsgBox("Yakinkah Data Ini Nak Di Hapus?", vbQuestion + vbYesNo, "konfirmasi") = vbYes Then
sql = "DELETE from akun WHERE kodeakun='" & lvw.SelectedItem.Text & "'"
MyConn.Execute sql
End If
lvw.ListItems.Clear
Dim rs As MYSQL_RS
sql = "SELECT * FROM akun"
Set rs = MyConn.Execute(sql)
If MyConn.Error.Number <> 0 Then MsgBox MyConn.Error.Description
Do While Not rs.EOF
Set lv = lvw.ListItems.Add(, , rs.Fields(0).Value)
lv.ListSubItems.Add , , rs.Fields(1).Value
lv.ListSubItems.Add , , rs.Fields(2).Value
lv.ListSubItems.Add , , rs.Fields(3).Value
lv.ListSubItems.Add , , rs.Fields(4).Value
lv.ListSubItems.Add , , rs.Fields(5).Value
rs.MoveNext
Loop
End Sub
-----------------------------------------------
Coding Keluar
Private Sub CmdKeluar_Click()
Unload Me
End Sub
----------------------------------------------
Coding Cari
Private Sub CmdCari_Click()
Dim sql As String
Dim rs As MYSQL_RS
sql = "select * from akun where kodeakun like '%" & Text4.Text & "%' or namaakun like '%" & Text4.Text & "%' or saldonormal like '%" & Text4.Text & "%'or jenisrekening like '%" & Text4.Text & "%'or kodeparent like '%" & Text4.Text & "%'or kelompokrekening like '%" & Text4.Text & "%'"
MyConn.Execute sql
If MyConn.Error.Number <> 0 Then MsgBox MyConn.Error.Description + " " + sql
lvw.ListItems.Clear
Set rs = MyConn.Execute(sql)
If MyConn.Error.Number <> 0 Then MsgBox MyConn.Error.Description
Do While Not rs.EOF
Set lv = lvw.ListItems.Add(, , rs.Fields(0).Value)
lv.ListSubItems.Add , , rs.Fields(1).Value
lv.ListSubItems.Add , , rs.Fields(2).Value
lv.ListSubItems.Add , , rs.Fields(3).Value
lv.ListSubItems.Add , , rs.Fields(4).Value
lv.ListSubItems.Add , , rs.Fields(5).Value
rs.MoveNext
Loop
End Sub
----------------------------------------------------
Setingan Pada Listview (Lvw)
klik kanan propertis pada lvw maka akan muncul gambar ini
pada view usahan pilih 3-lvwreport agar pada tampilan tabel bisa ditampilkan per coloum.Pada labelEdit isi 1-lvwmanual agar kita bisa mengisi tabel tersebut secara manual dan centang pada Gridlines untuk menampilkan garis pada tiap coloum.
dan
pada Column Headers klik InsertColumn pada text isi nama" untuk tampilan header column