Form Anggota "Perpustakaan Sederhana"



Listingnya Nih, Tapi Jangan Lupa Buat Dulu Database dan Field-Fieldnya sesuai dengan Form yang diatas, dan Nama Object di Formnya juga jangan lupa disesuaikan kawan.


Private Sub cfirst_Click()
On Error Resume Next
Adodc1.Recordset.MoveFirst
End Sub

Private Sub clast_Click()
On Error Resume Next
Adodc1.Recordset.MoveLast
End Sub

Private Sub cmdadd_Click()
aktif
bersih
nomat
tnama.SetFocus
End Sub

Sub nomat()
Dim no, oto As String
Adodc1.RecordSource = "select * from tblanggota"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount = 0 Then
    oto = "AA001"
    Else
        Adodc1.Recordset.MoveLast
        no = Right(Adodc1.Recordset.Fields(0), 3) + 1
        oto = "AA" & Right("00" & no, 3)
    End If
tkode = oto
End Sub

Private Sub cmdcancel_Click()
non
bersih
cmdexit.Enabled = True
cmdadd.Enabled = True
cfirst.Enabled = True
cprev.Enabled = True
cnext.Enabled = True
clast.Enabled = True
cmdedit.Caption = "EDIT"
End Sub

Private Sub cmdclean_Click()
bersih
Combo1.Text = ""
End Sub

Private Sub cmddelete_Click()
i = InputBox("Masukan Kode Buku :", "Perpustakan")
Adodc1.RecordSource = " Select * from tblanggota where kd_anggota= '" & i & "'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
    tampil
    h = MsgBox("Hapus Data Ini ??", vbYesNo + vbQuestion, "Perpustakaan")
    If h = vbYes Then
        Adodc1.Recordset.Delete
        bersih
    End If
Else
MsgBox "Data Tidak Ditemukan"
End If
End Sub

Private Sub cmdedit_Click()
If tkode <> "" Then
    If cmdedit.Caption = "EDIT" Then
    aktif
    cmdedit.Caption = "UPDATE"
        Else
            With Adodc1.Recordset
                 .Fields(0) = tkode
                 .Fields(1) = tnama
                 .Fields(2) = tnim
                 .Fields(3) = Combo1
                 If opt1.Value = True Then .Fields(4) = "L"
                 If opt2.Value = True Then .Fields(4) = "P"
                 .Fields(5) = talamat
                 .Fields(6) = DTPicker1.Value
                 .Fields(7) = ttelp
            End With
        bersih
        cmdedit.Caption = "EDIT"
    End If
Else
MsgBox "Tidak Ada data Yang Di Edit", vbOKOnly + vbInformation, "Pesan"
End If
End Sub

Sub tampil()
With Adodc1.Recordset
     tkode = .Fields(0)
     tnama = .Fields(1)
     tnim = .Fields(2)
     Combo1 = .Fields(3)
     If .Fields(4) = L Then opt1.Value = True
     If .Fields(4) = P Then opt2.Value = True
     talamat = .Fields(5)
     DTPicker1.Value = .Fields(6)
     ttelp = .Fields(7)
End With
End Sub

Private Sub cmdexit_Click()
h = MsgBox("Yakin Akan Keluar ???", vbYesNo + vbQuestion, "Perpustakaan")
If h = vbYes Then
    Unload Me
End If
End Sub

Private Sub cmdsave_Click()
Adodc1.RecordSource = " Select * From tblanggota"
Adodc1.Refresh
With Adodc1.Recordset
    .AddNew
    .Fields(0) = tkode
    .Fields(1) = tnama
    .Fields(2) = tnim
    .Fields(3) = Combo1
    If opt1.Value = True Then .Fields(4) = "L"
    If opt2.Value = True Then .Fields(4) = "P"
    .Fields(5) = talamat
    .Fields(6) = DTPicker1.Value
    .Fields(7) = ttelp
    .Update
End With
bersih
MsgBox "Data Berhasil Disimpan !!!!"
End Sub

Private Sub cnext_Click()
On Error Resume Next
If Adodc1.Recordset.EOF Then
    MsgBox "Anda Berada di Akhir Record"
    Else
        Adodc1.Recordset.MoveNext
End If
End Sub

Private Sub cprev_Click()
On Error Resume Next
If Adodc1.Recordset.BOF Then
    MsgBox "Anda Berada di Awal Record !!"
    Else
        Adodc1.Recordset.MovePrevious
End If
End Sub

Private Sub Form_Load()
Adodc1.Visible = False
Adodc1.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data source = " & App.Path & "\perpustakaan.mdb"
Adodc1.RecordSource = "select * from tblanggota"
Adodc1.Refresh

non
bersih
cmdadd.Enabled = True
cmdexit.Enabled = True
cfirst.Enabled = True
cprev.Enabled = True
cnext.Enabled = True
clast.Enabled = True
End Sub

Private Sub tcari_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Adodc1.RecordSource = "select * from tblanggota where kd_anggota='" & tcari & "'"
Adodc1.Refresh
    If Adodc1.Recordset.RecordCount > 0 Then
       tampil
    End If
End If
End Sub

Private Sub Timer1_Timer()
cmdexit.Caption = Right(cmdexit.Caption, Len(cmdexit.Caption) - 1) & Left(cmdexit.Caption, 1)
t.Caption = Right(t.Caption, Len(t.Caption) - 1) & Left(t.Caption, 1)
End Sub

Sub bersih()
Dim h As Control
For Each h In Me
If TypeOf h Is TextBox Then h.Text = ""
If TypeOf h Is OptionButton Then h.Value = False
Next h
End Sub

Sub aktif()
Dim h As Control
For Each h In Me
If TypeOf h Is TextBox Then h.Enabled = True
If TypeOf h Is OptionButton Then h.Enabled = True
If TypeOf h Is DTPicker Then h.Enabled = True
If TypeOf h Is CommandButton Then h.Enabled = True
Next h
End Sub

Sub non()
Dim h As Control
For Each h In Me
If TypeOf h Is TextBox Then h.Enabled = False
If TypeOf h Is OptionButton Then h.Enabled = False
If TypeOf h Is DTPicker Then h.Enabled = False
If TypeOf h Is CommandButton Then h.Enabled = False
Next h
End Sub

Private Sub Timer2_Timer()
t.BackColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
End Sub

Share this

Related Posts

Previous
Next Post »