'Koneksi ke database
Private Sub Form_Load()
dmobil.DatabaseName = App.Path + "\dbmobil.mdb"
End Sub
'Prosedur bersih , aktif & nonaktif
Sub bersih()
tno = ""
tnama = ""
cbseri = ""
tjenis = ""
tharga = ""
tlama = ""
ttotal = ""
End Sub
Sub aktif()
tnama.Enabled = True
cbseri.Enabled = True
tlama.Enabled = True
End Sub
Sub nonaktif()
tno.Enabled = False
tnama.Enabled = False
cbseri.Enabled = False
tjenis.Enabled = False
tharga.Enabled = False
tlama.Enabled = False
ttotal.Enabled = False
End Sub
'Ketika Form Aktif
Private Sub Form_Activate()
bersih
nonaktif
cbaru.SetFocus
End Sub
'No transaksi Otomatis dengan tanggal
Private Sub cbaru_Click()
Dim no, tgl As String
tgl = Right(Date, 2) + Mid(Date, 4, 2)
bersih
aktif
tnama.SetFocus
With dmobil.Recordset
If .RecordCount > 0 Then
.MoveLast
no = Str(Val(Right(!notrans, 4)) + 1)
If no < 9 Then
tno.Text = "M" & tgl & "000" & no
ElseIf no < 99 Then
tno.Text = "M" & tgl & "00" & no
ElseIf no < 999 Then
tno.Text = "M" & tgl & "0" & no
End If
Else
tno.Text = "M" + tgl + "0001"
End If
End With
tnama.SetFocus
End Sub
'Menampilkan jenis mobil & Harga Sewa
Private Sub cbseri_Click()
Select Case cbseri.Text
Case "kjg", "KJG": tjenis.Text = "Kijang": tharga.Text = 300000
Case "xna", "XNA": tjenis.Text = "Xenia": tharga.Text = 450000
Case "cry", "CRY": jenis.Text = "Carry": tharga.Text = 200000
End Select
tlama.SetFocus
End Sub
'Menghitung Total
Private Sub tlama_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
ttotal.Text = Val(tharga.Text) * Val(tlama.Text)
csimpan.SetFocus
End If
End Sub
'Menyimpan ke database
Private Sub csimpan_Click()
With dmobil.Recordset
.AddNew
!notrans = tno.Text
!nama = tnama.Text
!seri = cbseri.Text
!jenis = tjenis.Text
!harga = Val(tharga.Text)
!lama = Val(tlama.Text)
!total = Val(ttotal.Text)
.Update
MsgBox "Data Tersimpan"
End With
End Sub
'Menghapus Data
Private Sub chapus_Click()
If MsgBox("Hapus nieh?", vbYesNo) = vbYes Then
dmobil.Recordset.Delete
End If
End Sub
'Keluar dari form
Private Sub ckeluar_Click()
If MsgBox("Keluar nieh?", vbYesNo) = vbYes Then
Unload Me
End If
End Sub
Posting Komentar