Pertama Buat dulu databasenya dengan SQL Server. field-fieldnya sbb:
- kodeakun tipe char panjang 8
- namaakun tipe varchar panjang 30
- saldoawal tipe money
kolo sudah selesai sekarang untuk scriptnya tuliskan kode sbb:
Dim conect As String
Dim sql As String
Dim con As New ADODB.Connection
Dim rsa As New ADODB.Recordset
Sub sambung()
Set con = New ADODB.Connection
Set rsa = New ADODB.Recordset
con.Open conect
rsa.Open "akun", con
End Sub
Private Sub Cmd_Simpan_Click()
On Error GoTo errlabel
Call kosong
Call sambung
If Txt_kodeakun.Enabled = True Then
sql = "insert into akun values('" & Txt_kodeakun.Text & "','" & Txt_namaakun.Text & "'," & CCur("0" & Txt_saldo.Text) & ")"
con.Execute (sql)
Ado_Rekening.Refresh
Else
sql = "update akun set namaakun='" & Txt_namaakun.Text & "',saldoawal=" & CCur("0" & Txt_saldo.Text) & " where kodeakun='" & Txt_kodeakun.Text & "'"
con.Execute (sql)
Ado_Rekening.Refresh
End If
Txt_kodeakun.Enabled = False
Txt_namaakun.Enabled = False
Txt_saldo.Enabled = False
Cmd_Tambah.Enabled = True
Cmd_Simpan.Enabled = False
Cmd_Hapus.Enabled = False
Cmd_Batal.Enabled = False
Cmd_Edit.Enabled = False
Cmd_Cari.Enabled = True
Ado_Rekening.Refresh
Ado_Rekening.Recordset.MoveLast
Exit Sub
errlabel:
MsgBox Err.Description
End Sub
0 komentar:
Post a Comment