Form Login
Private Sub Command1_Click()
rs.Open "SELECT * FROM T_user" & _
        " WHERE username = '" & Text1.Text & "'" & _
        " AND password = '" & Text2.Text & "'", mydb, adOpenStatic

If rs.EOF Then
    MsgBox "Username atau Password salah !", vbCritical
    Text1.Text = ""
    Text2.Text = ""
    Text1.SetFocus
    rs.Close
    Exit Sub

ElseIf rs.Fields("username") = Trim(rs.Fields("kode_petugas")) Then
    rs.Close
    F_UBaru.Text1.Text = UCase(F_Login.Text1.Text)
    F_UBaru.Show
    Unload Me
    
Else
    F_Menu.StatusBar1.Panels.Item(2) = Text1.Text
    rs2.Open "SELECT lvl FROM T_user WHERE username='" & Text1.Text & "'", mydb, adOpenStatic
    If rs2.Fields("lvl") = "0" Then
        F_Menu.StatusBar1.Panels.Item(4) = "Admin"
        Akses_Admin
    Else
        F_Menu.StatusBar1.Panels.Item(4) = "Petugas"
        Akses_Pegawai
    End If
    rs2.Close
    F_Menu.Show
    Unload F_Login
    rs.Close
    
End If
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
BukaDB
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    Command1_Click
End If
End Sub

Form Anggota
Dim kondisi, nama As String

Private Sub Combo1_Click()
K_Anggota
Text1.Text = no_anggota
End Sub

Private Sub Command1_Click()
If Text2.Text = "" Or Len(Text2.Text) < "4" Then
    MsgBox "Isikan Nama minimal 4 karakter !", vbOKOnly, "INFO"
    Text2.SetFocus
    Exit Sub
ElseIf Text3.Text = "" Or Len(Text3.Text) < "5" Then
    MsgBox "Alamat belum diisikan, atau terlalu pendek !", vbOKOnly, "INFO"
    Text3.SetFocus
    Exit Sub
'ElseIf Text4.Text = "" Or Len(Text4.Text) < "6" Then
'MsgBox "Isikan Telepon  !", vbOKOnly, "INFO"
'    Text4.SetFocus
'    Exit Sub
ElseIf Combo1.Text = "" Or Combo1.Text = "-=PILIH ANGGOTA=-" Then
    MsgBox "Pilih Status Anggota !", vbOKOnly, "INFO"
    Combo1.SetFocus
    Exit Sub
ElseIf Image1.Picture = LoadPicture("") Then
    MsgBox "Isikan Foto Anggota !", vbOKOnly, "INFO"
    Exit Sub
End If

Dim jk As String
If Option1.Value = True Then
    jk = "L"
ElseIf Option2.Value = True Then
    jk = "P"
End If

If kondisi = 0 Then
    rs.Open "SELECT no_anggota FROM T_ANGGOTA WHERE nama LIKE '" & Text2.Text & "'", mydb, adOpenStatic

    If rs.EOF Then
        rs2.Open "SELECT status_anggota FROM T_Anggota_dt" & _
             " WHERE anggota='" & Combo1.Text & "'", mydb, adOpenStatic
             
        mydb.Execute "INSERT INTO T_Anggota VALUES('" & Text1.Text & "','" & _
                                                Text2.Text & "','" & _
                                                jk & "','" & _
                                                Text3.Text & "','" & _
                                                Text4.Text & "','" & _
                                                rs2.Fields("status_anggota") & "','" & _
                                                nama & "')"
        rs2.Close
                                                
    Else
        MsgBox "Sudah tersimpan data Anggota " & Text2.Text & " !", vbOKOnly, "INFO"
    
    End If
    rs.Close
    Command2_Click

Else
    mydb.Execute "UPDATE T_anggota SET alamat='" & Text3.Text & "', telepon='" & Text4.Text & "', foto='" & nama & "'" & _
                 " WHERE no_anggota='" & Text1.Text & "'"
    Command2_Click
    
End If
End Sub

Private Sub Command2_Click()
Text2.Enabled = True
Option1.Enabled = True
Option2.Enabled = True
Combo1.Enabled = True
Text1.Text = ""
Text2.Text = ""
Option1.Value = True
Text3.Text = ""
Text4.Text = ""
Combo1.Text = "-=PILIH ANGGOTA=-"
Text2.SetFocus
Image1.Picture = LoadPicture("")
kondisi = 0
head
grid
End Sub

Private Sub Command3_Click()
Call Buka(True)
Unload Me
End Sub

Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
BukaDB
head
grid
kondisi = 0

rs.Open "SELECT anggota FROM T_anggota_dt ORDER BY anggota", mydb, adOpenStatic

While Not rs.EOF
    Combo1.AddItem (rs.Fields("anggota"))
    rs.MoveNext
Wend
rs.Close

End Sub

Private Sub grid2_DblClick()
Dim jika As String
jika = MsgBox("Hapus Data ??", vbYesNo, "INFORMASI")
If jika = vbYes Then
    rs.Open "SELECT no_anggota FROM T_trans" & _
            " WHERE no_anggota='" & grid2.TextMatrix(grid2.Row, 0) & "'", mydb, adOpenStatic
        If rs.EOF Then
            mydb.Execute "DELETE FROM T_anggota WHERE no_anggota='" & grid2.TextMatrix(grid2.Row, 0) & "'"
            rs.Close
            Command2_Click
        Else
            MsgBox "Data anggota " & grid2.TextMatrix(grid2.Row, 1) & " tidak dapat dihapus karena terpakai !", vbOKOnly, "INFO"
            rs.Close
        End If
    
Else
    rs.Open "SELECT no_anggota, nama, jenis_kelamin, alamat, telepon, Anggota, foto FROM T_anggota, T_anggota_dt " & _
            " WHERE T_anggota.status_anggota = T_anggota_dt.status_anggota " & _
            " AND no_anggota='" & grid2.TextMatrix(grid2.Row, 0) & "'", mydb, adOpenStatic
            
    Text1.Text = grid2.TextMatrix(grid2.Row, 0)
    Combo1.Text = rs.Fields("anggota")
    Text2.Text = rs.Fields("nama")
    Text3.Text = rs.Fields("alamat")
    Text4.Text = rs.Fields("telepon")
    'Dim data As String
    'data = rs.Fields("foto")
    'Image1.Picture = LoadPicture(data)
    
    Dim gbr As Image
    Dim sss As String
    sss = "E:\DATA\DATAKU\TUGAS AKHIR\SKRIPSI KU\App_Perpus_new\foto\" + rs.Fields("foto")
    Image1.Picture = LoadPicture(sss)
    
    If rs.Fields("jenis_kelamin") = "L" Then
        Option1.Value = True
    Else
        Option2.Value = True
    End If
    kondisi = 1
    Text2.Enabled = False
    Combo1.Enabled = False
    Option1.Enabled = False
    Option2.Enabled = False
    rs.Close
    
End If
End Sub

Private Sub Image1_DblClick()
CommonDialog1.ShowOpen
Dim asal, tujuan As String
nama = CommonDialog1.FileTitle
tujuan = "E:\DATA\DATAKU\TUGAS AKHIR\SKRIPSI KU\App_Perpus_new\foto\" & Trim(nama) & ""
asal = CommonDialog1.FileTitle
If asal <> "" Then
    FileCopy asal, tujuan
    Image1.Picture = LoadPicture(tujuan)
End If

End Sub

Private Sub Text4_KeyPress(KeyAscii As Integer)
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then

Else
    Beep
    KeyAscii = 0
End If
End Sub

Function head()
With grid1
    .Row = 0
    .Col = 0
    .Text = "NO. ANGGOTA"
    .CellFontBold = True
    .ColWidth(0) = 1500
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 1
    .Text = "NAMA"
    .CellFontBold = True
    .ColWidth(1) = 3200
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 2
    .Text = "TELEPON"
    .CellFontBold = True
    .ColWidth(2) = 1800
    .CellAlignment = flexAlignCenterCenter
End With
End Function

Function grid()
rs.Open "SELECT no_anggota, nama, telepon FROM T_anggota" & _
        " ORDER BY no_anggota", mydb, adOpenStatic
        
Set grid2.Recordset = rs
If Not rs.EOF Then
    With grid2
    .Row = 0
    .Col = 0
    .ColWidth(0) = 1500
    .Row = 0
    .Col = 1
    .ColWidth(1) = 3200
    .Row = 0
    .Col = 2
    .ColWidth(2) = 1800
    End With
Else

End If
rs.Close
End Function

Form Buku
Dim kondisi As String

Private Sub Combo1_Click()
rs.Open "SELECT kode_kategori FROM T_kategori" & _
        " WHERE nama_kategori='" & Combo1.Text & "'", mydb, adOpenStatic
kategori = rs.Fields("kode_kategori")

K_Buku
Text1.Text = no_buku
rs.Close
End Sub

Private Sub Command1_Click()
If Text1.Text = "" Then
    MsgBox "Pilih Kategori Buku !", vbOKOnly, "INFO"
    Combo1.SetFocus
    Exit Sub
ElseIf Text2.Text = "" Or Len(Text2.Text) < 4 Then
    MsgBox "Isikan Judul Buku !", vbOKOnly, "INFO"
    Text2.SetFocus
    Exit Sub
ElseIf Text3.Text = "" Or Len(Text3.Text) < 4 Then
    MsgBox "Isikan Penerbit Buku !", vbOKOnly, "INFO"
    Text3.SetFocus
    Exit Sub
ElseIf Text4.Text = "" Or Len(Text4.Text) < 4 Then
    MsgBox "Isikan Pengarang Buku !", vbOKOnly, "INFO"
    Text4.SetFocus
    Exit Sub
ElseIf Text5.Text = "" Or Len(Text5.Text) < 4 Then
    MsgBox "Isikan Tahun Terbit Buku !", vbOKOnly, "INFO"
    Text5.SetFocus
    Exit Sub
ElseIf Text6.Text = "" Or Len(Text6.Text) < 2 Then
    MsgBox "Isikan Jumlah Halaman !", vbOKOnly, "INFO"
    Text6.SetFocus
    Exit Sub
ElseIf Text7.Text = "" Or Len(Text7.Text) < 4 Then
    MsgBox "Isikan Harga Ganti Buku !", vbOKOnly, "INFO"
    Text7.SetFocus
    Exit Sub
ElseIf Text8.Text = "" Or Len(Text8.Text) < 3 Then
    MsgBox "Isikan Denda Rusak Buku !", vbOKOnly, "INFO"
    Text8.SetFocus
    Exit Sub
End If

If kondisi = 0 Then
    rs.Open "SELECT kode_buku FROM T_Buku" & _
            " WHERE judul='" & Text2.Text & "'", mydb, adOpenStatic
    If rs.EOF Then
        mydb.Execute "INSERT INTO T_buku VALUES('" & Text1.Text & "','" & _
                                                 kategori & "','" & _
                                                 Text2.Text & "','" & _
                                                 Text3.Text & "','" & _
                                                 Text4.Text & "','" & _
                                                 Text5.Text & "'," & _
                                                 Text6.Text & "," & _
                                                 Text7.Text & "," & _
                                                 Text8.Text & ")"
        rs.Close
        Command2_Click
    
    Else
        MsgBox "Judul BUKU " & Text2.Text & " Tersedia !", vbOKOnly, "INFO"
        Text2.SetFocus
        rs.Close
    End If

Else
    rs.Open "SELECT kode_buku FROM T_Buku" & _
            " WHERE judul='" & Text2.Text & "'", mydb, adOpenStatic
    
    mydb.Execute "UPDATE T_buku SET judul='" & Text2.Text & "', penerbit='" & Text3.Text & "'," & _
                 " pengarang='" & Text4.Text & "'," & _
                 " tahun_terbit='" & Text5.Text & "', jumlah_halaman=" & Text6.Text & "," & _
                 " denda_hilang=" & Text7.Text & ", denda_rusak=" & Text8.Text & "" & _
                 " WHERE kode_buku='" & Text1.Text & "'"
    rs.Close
    Command2_Click
    
End If

End Sub

Private Sub Command2_Click()
Combo1.Enabled = True
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Combo1.Text = ""
Combo1.SetFocus
kondisi = 0
head
grid
End Sub

Private Sub Label11_Click()

End Sub

Private Sub Command3_Click()
Call Buka(True)
Unload Me
End Sub

Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
BukaDB
head
grid
kondisi = 0

rs.Open "SELECT nama_kategori FROM T_kategori" & _
        " ORDER BY nama_kategori", mydb, adOpenStatic
While Not rs.EOF
    Combo1.AddItem (rs.Fields("nama_kategori"))
    rs.MoveNext
Wend
rs.Close
End Sub

Private Sub grid2_DblClick()
Dim jika As String
jika = MsgBox("Hapus Data ??", vbYesNo, "INFORMASI")
If jika = vbYes Then
    rs.Open "SELECT kode_buku FROM T_inventaris" & _
            " WHERE kode_buku='" & grid2.TextMatrix(grid2.Row, 0) & "'", mydb, adOpenStatic
        If rs.EOF Then
            mydb.Execute "DELETE FROM T_buku WHERE kode_buku='" & grid2.TextMatrix(grid2.Row, 0) & "'"
            rs.Close
            Command2_Click
        Else
            MsgBox "Data buku " & grid2.TextMatrix(grid2.Row, 1) & " tidak dapat dihapus karena terpakai !", vbOKOnly, "INFO"
            rs.Close
        End If
    
Else
    rs.Open "SELECT * FROM T_buku WHERE kode_buku='" & grid2.TextMatrix(grid2.Row, 0) & "'", mydb, adOpenStatic
    Text1.Text = grid2.TextMatrix(grid2.Row, 0)
    Combo1.Text = grid2.TextMatrix(grid2.Row, 2)
    Text2.Text = rs.Fields("judul")
    Text3.Text = rs.Fields("penerbit")
    Text4.Text = rs.Fields("pengarang")
    Text5.Text = Format(rs.Fields("tahun_terbit"), "yyyy")
    Text6.Text = rs.Fields("jumlah_halaman")
    Text7.Text = rs.Fields("denda_hilang")
    Text8.Text = rs.Fields("denda_rusak")
    kondisi = 1
    Combo1.Enabled = False
    rs.Close
    
End If
End Sub

Private Sub Text5_KeyPress(KeyAscii As Integer)
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then

Else
    Beep
    KeyAscii = 0
End If
End Sub

Private Sub Text6_KeyPress(KeyAscii As Integer)
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then

Else
    Beep
    KeyAscii = 0
End If
End Sub

Private Sub Text7_KeyPress(KeyAscii As Integer)
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then

Else
    Beep
    KeyAscii = 0
End If
End Sub

Private Sub Text8_KeyPress(KeyAscii As Integer)
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then

Else
    Beep
    KeyAscii = 0
End If
End Sub

Function head()
With grid1
    .Row = 0
    .Col = 0
    .Text = "KODE"
    .CellFontBold = True
    .ColWidth(0) = 1200
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 1
    .Text = "JUDUL"
    .CellFontBold = True
    .ColWidth(1) = 3500
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 2
    .Text = "KATEGORI"
    .CellFontBold = True
    .ColWidth(2) = 1800
    .CellAlignment = flexAlignCenterCenter
End With
End Function

Function grid()
rs.Open "SELECT kode_buku, judul, nama_kategori FROM T_buku, T_kategori" & _
        " WHERE T_buku.kode_kategori = T_kategori.kode_kategori" & _
        " ORDER BY kode_buku", mydb, adOpenStatic
If rs.EOF Then
    rs.Close
    Exit Function
End If
Set grid2.Recordset = rs
With grid2
    .Row = 0
    .Col = 0
    .ColWidth(0) = 1200
    .Row = 0
    .Col = 1
    .ColWidth(1) = 3500
    .Row = 0
    .Col = 2
    .ColWidth(2) = 1800
End With
rs.Close
End Function

Form Pemasukan Buku
Dim kondisi As String
Dim rsa As New ADODB.Recordset
Dim rs3 As New ADODB.Recordset

Private Sub Command1_Click()
If Text3.Text = "" Or Len(Text3.Text) < 4 Then
    MsgBox "Isikan Kode Buku !", vbOKOnly, "INFO"
    Text3.SetFocus
    Exit Sub
ElseIf Combo1.Text = "" Or Combo1.Text = "" Then
    MsgBox "Isikan Asal Buku !", vbOKOnly, "INFO"
    Combo1.SetFocus
    Exit Sub
ElseIf Text5.Text = "" Or Val(Text5.Text) <= 0 Then
    MsgBox "Isikan Jumlah Pemasukan Buku !", vbOKOnly, "INFO"
    Text5.SetFocus
    Exit Sub
End If

rs.Open "SELECT count(no_inventaris) as jumlah FROM t_inventaris" & _
        " WHERE kode_buku = '" & Text3.Text & "'", mydb, adOpenStatic

Dim st As Double
st = rs.Fields("jumlah")
st = st
If (99 - rs.Fields("jumlah")) < Val(Text5.Text) Then
    MsgBox "Maximum jumlah buku per kode = 99, tersisa " & (99 - st) & " !", vbOKOnly
    rs.Close
    Exit Sub
End If
rs.Close

If kondisi = 0 Then
    rs.Open "SELECT asal_masuk FROM T_asal " & _
            " WHERE asal='" & Combo1.Text & "'", mydb, adOpenStatic
        
    mydb.Execute "INSERT INTO T_masuk VALUES('" & Text1.Text & "','" & _
                                              Format(Date, "mm/dd/yyyy") & "','" & _
                                              Text3.Text & "'," & _
                                              Text5.Text & "," & _
                                              rs.Fields("asal_masuk") & ")"
    rs.Close

    Dim i As Integer
    i = 0
    While i < Val(Text5.Text)
        Call invent
        mydb.Execute "INSERT INTO T_inventaris VALUES('" & no_inven & "','" & _
                                                       Text3.Text & "'," & _
                                                       1 & ")"
        i = i + 1
    Wend

    Command2_Click

Else
    rs.Open "SELECT jumlah_masuk FROM T_masuk WHERE no_masuk='" & Text1.Text & "'", mydb, adOpenStatic
    
    If Text5.Text > rs.Fields("jumlah_masuk") Then
    'tambah jumlahnya
        Dim j As Integer
        j = 0
        While j < Val(Text5.Text - rs.Fields("jumlah_masuk"))
            Call invent
            mydb.Execute "INSERT INTO T_inventaris VALUES('" & no_inven & "','" & _
                                                       Text3.Text & "'," & _
                                                       1 & ")"
            j = j + 1
        Wend
        
    ElseIf Text5.Text < rs.Fields("jumlah_masuk") Then
    'kurangi jumlahnya
        Dim k As Integer
        k = 0
        rs2.Open "SELECT no_inventaris FROM T_inventaris WHERE kode_buku='" & Text3.Text & "'", mydb, adOpenStatic
        rs2.MoveLast
        rs3.Open "SELECT no_inventaris FROM T_transpinjam" & _
                 " WHERE no_inventaris='" & rs2.Fields("no_inventaris") & "'", mydb, adOpenStatic
        
        If Not rs3.EOF Then
            MsgBox "Data Buku tidak dapat dikurangi karena terpakai !", vbOKOnly, "INFO"
            rs.Close
            rs2.Close
            rs3.Close
            Command2_Click
            Exit Sub
        End If
        
        While k < (rs.Fields("jumlah_masuk") - Val(Text5.Text))
            mydb.Execute "DELETE FROM T_inventaris WHERE no_inventaris = '" & rs2.Fields("no_inventaris") & "'"
            k = k + 1
            rs2.MovePrevious
        Wend
        rs2.Close
        rs3.Close
    End If
    
    rs.Close
    
    rs.Open "SELECT asal_masuk FROM T_asal WHERE asal = '" & Combo1.Text & "'", mydb, adOpenStatic
    mydb.Execute "UPDATE T_masuk SET jumlah_masuk = " & Text5.Text & "," & _
                 " asal_masuk=" & rs.Fields("asal_masuk") & "" & _
                 " WHERE no_masuk ='" & Text1.Text & "'"
    rs.Close
    
    Command2_Click
End If
End Sub

Function invent()
Dim no As String
Dim nol As String

rsa.Open "SELECT no_inventaris FROM T_inventaris " & _
        " WHERE kode_buku='" & Text3.Text & "'" & _
        " ORDER BY no_inventaris", mydb, adOpenStatic
        
If rsa.EOF Then
    no_inven = Text3.Text + "-" + "01"
    
Else
    rsa.MoveLast
    no = Right(rsa.Fields("no_inventaris"), 2) + 1
    If (no < 10) Then
        nol = "0"
    Else
        nol = ""
    End If
    no_inven = Text3.Text + "-" + nol + no
    
End If
rsa.Close
End Function

Private Sub Command2_Click()
Text1.Enabled = False
Combo1.Enabled = False
Call K_masuk
Text1.Text = no_masuk
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Combo1.Text = ""
Text5.Enabled = False
Combo1.Enabled = False
Command1.Enabled = False
Command4.Enabled = True
kondisi = 0
grid
End Sub

Private Sub Command3_Click()
Call Buka(True)
Unload Me
End Sub

Private Sub Command4_Click()
A_CariBuku.Show
Me.Enabled = False
End Sub

Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
Call BukaDB
Call K_masuk
head
grid
kondisi = 0
Text2.Text = Format(Date, "MM/dd/yyyy")
Text1.Text = no_masuk

rs.Open "SELECT asal FROM T_asal" & _
        " ORDER BY asal", mydb, adOpenStatic
While Not rs.EOF
    Combo1.AddItem (rs.Fields("asal"))
    rs.MoveNext
Wend
rs.Close
End Sub

Private Sub grid2_DblClick()
Dim jika As String
jika = MsgBox("Hapus Data ??", vbYesNo, "INFORMASI")
If jika = vbYes Then
    rs.Open "SELECT T_inventaris.no_inventaris, T_masuk.kode_buku FROM T_transpinjam, T_masuk, T_inventaris" & _
            " WHERE T_inventaris.no_inventaris = T_transpinjam.no_inventaris" & _
            " AND T_inventaris.kode_buku = T_masuk.kode_buku" & _
            " AND no_masuk='" & Trim(grid2.TextMatrix(grid2.Row, 0)) & "'", mydb, adOpenStatic
            
        If rs.EOF Then
            rs2.Open "select kode_buku from T_masuk where no_masuk='" & Trim(grid2.TextMatrix(grid2.Row, 0)) & "'", mydb, adOpenStatic
            mydb.Execute "DELETE FROM T_inventaris WHERE kode_buku='" & rs2.Fields("kode_buku") & "'"
            mydb.Execute "DELETE FROM T_masuk WHERE no_masuk='" & grid2.TextMatrix(grid2.Row, 0) & "'"
            rs.Close
            rs2.Close
            Command2_Click
        Else
            MsgBox "Data Buku " & grid2.TextMatrix(grid2.Row, 1) & " tidak dapat dihapus karena terpakai !", vbOKOnly, "INFO"
            rs.Close
        End If
    
Else
    rs.Open "SELECT T_masuk.no_masuk, tgl_masuk, T_buku.kode_buku, judul, jumlah_masuk, asal" & _
            " FROM T_masuk, T_buku, T_inventaris, T_asal " & _
            " WHERE T_masuk.kode_buku = T_buku.kode_buku" & _
            " AND T_masuk.kode_buku = T_inventaris.kode_buku" & _
            " AND T_masuk.asal_masuk = T_asal.asal_masuk" & _
            " AND T_masuk.no_masuk='" & grid2.TextMatrix(grid2.Row, 0) & "'", mydb, adOpenStatic
            
    Text1.Text = rs.Fields("no_masuk")
    Combo1.Text = rs.Fields("asal")
    Text2.Text = rs.Fields("tgl_masuk")
    Text3.Text = rs.Fields("kode_buku")
    Text4.Text = rs.Fields("judul")
    Text5.Text = rs.Fields("jumlah_masuk")
    kondisi = 1
    Text5.Enabled = True
    Command4.Enabled = False
    Command1.Enabled = True
    Combo1.Enabled = True
    rs.Close
    
End If

End Sub

Private Sub Text5_KeyPress(KeyAscii As Integer)
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then

Else
    Beep
    KeyAscii = 0
End If
End Sub

Function head()
With grid1
    .Row = 0
    .Col = 0
    .Text = "NO"
    .CellFontBold = True
    .ColWidth(0) = 1200
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 1
    .Text = "JUDUL"
    .CellFontBold = True
    .ColWidth(1) = 3500
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 2
    .Text = "JUMLAH"
    .CellFontBold = True
    .ColWidth(2) = 800
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 3
    .Text = "ASAL"
    .CellFontBold = True
    .ColWidth(3) = 1800
    .CellAlignment = flexAlignCenterCenter
End With
End Function

Function grid()
rs.Open "SELECT no_masuk, judul, jumlah_masuk, asal FROM T_masuk, T_asal, T_buku" & _
        " WHERE T_masuk.asal_masuk = T_asal.asal_masuk" & _
        " AND T_buku.kode_buku = T_masuk.kode_buku" & _
        " ORDER BY no_masuk", mydb, adOpenStatic
        
Set grid2.Recordset = rs
With grid2

    .ColWidth(0) = 1200

    .ColWidth(1) = 3500

    .ColWidth(2) = 800

    .ColWidth(3) = 1800
End With
rs.Close
End Function

Form Cetak
Private Sub Command1_Click()
Dim sql As String
sql = "select  no_anggota, nama, alamat, anggota, foto" & _
      " From T_anggota, T_anggota_dt" & _
      " Where T_anggota.status_anggota = T_anggota_dt.status_anggota" & _
      " and no_anggota = '" & Text1.Text & "'"
      
Set rs = mydb.Execute(sql)
If rs.EOF Then
    MsgBox " nomor Anggota tidak ditemukan!", vbOKOnly, "INFO"
    Exit Sub
End If

    data.Commands(7).CommandText = sql
    rs2.Open "select  no_anggota, nama, alamat, anggota, foto" & _
      " From T_anggota, T_anggota_dt" & _
      " Where T_anggota.status_anggota = T_anggota_dt.status_anggota" & _
      " and no_anggota = '" & Text1.Text & "'", mydb, adOpenStatic
      
    Dim tmpimg As RptImage
    Dim sss As String
    sss = "E:\DATA\DATAKU\TUGAS AKHIR\SKRIPSI KU\App_Perpus_new\foto\" + rs2.Fields("foto")
    Set tmpimg = kartu.Sections("Section1").Controls("Image3")
    Set tmpimg.Picture = LoadPicture(sss)
    rs2.Close
    data.rskartu.Open
    kartu.Refresh
    kartu.Show
    
End Sub

Private Sub Command2_Click()
Call Buka(True)
Unload Me
End Sub

Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
BukaDB
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    Command1_Click
End If
End Sub

Form Kategori
Dim kondisi As String

Private Sub Command1_Click()
If Text2.Text = "" Or Len(Text2.Text) < 4 Then
    MsgBox "Input Nama Kategori Terlalu Pendek !", vbOKOnly, "INFO"
    Text2.Text = ""
    Text2.SetFocus
    Exit Sub
ElseIf Text3.Text = "" Or Len(Text3.Text) < 4 Then
    MsgBox "Input Lokasi Rak Terlalu Pendek !", vbOKOnly, "INFO"
    Text3.Text = ""
    Text3.SetFocus
    Exit Sub
End If

If kondisi = 0 Then
    rs.Open "SELECT kode_kategori FROM T_kategori" & _
            " WHERE nama_kategori LIKE '" & Text2.Text & "'", mydb, adOpenStatic
    If rs.EOF Then
        mydb.Execute "INSERT INTO T_kategori VALUES('" & Text1.Text & "','" & _
                                                         Text2.Text & "','" & _
                                                         Text3.Text & "')"
        MsgBox "Buku " & Text2.Text & " Tersimpan !", vbOKOnly, "INFO"

    Else
        MsgBox "Sudah Tersimpan data buku " & Text2.Text & " !", vbOKOnly, "INFO"

    End If
    rs.Close
    Command2_Click

Else
    mydb.Execute "UPDATE T_kategori SET nama_kategori='" & Text2.Text & "'," & _
                 " lokasi_rak='" & Text3.Text & "'" & _
                 " WHERE kode_kategori='" & Text1.Text & "'"
    Command2_Click
End If
End Sub

Private Sub Command2_Click()
Text2.Text = ""
Text3.Text = ""
Call K_kategori
Text1.Text = no_kategori
Text2.SetFocus
kondisi = 0
head
grid
End Sub

Private Sub Command3_Click()
Call Buka(True)
Unload Me
End Sub

Private Sub Form_Load()
BukaDB
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
K_kategori
Text1.Text = no_kategori
kondisi = 0
head
grid
End Sub

Function head()
rs.Open "SELECT kode_kategori as KODE, nama_kategori as KATEGORI, lokasi_rak as LOKASI FROM T_kategori" & _
        " WHERE kode_kategori='" & hquhufhaihs & "'", mydb, adOpenStatic
Set grid1.Recordset = rs

With grid1
    .Row = 0
    .Col = 0
    .CellFontBold = True
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 1
    .CellFontBold = True
    .ColWidth(1) = 3000
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 2
    .CellFontBold = True
    .ColWidth(2) = 1000
    .CellAlignment = flexAlignCenterCenter
End With
rs.Close
End Function

Function grid()
rs.Open "SELECT * FROM T_kategori" & _
        " ORDER BY kode_kategori", mydb, adOpenStatic
Set grid2.Recordset = rs

With grid2
    .Row = 0
    .Col = 1
    .ColWidth(1) = 3000
    .Row = 0
    .Col = 2
    .ColWidth(2) = 1000
End With
rs.Close
End Function

Private Sub grid2_DblClick()
Dim jika As String
jika = MsgBox("Hapus Data ??", vbYesNo, "INFORMASI")
If jika = vbYes Then
    rs.Open "SELECT kode_kategori FROM T_buku" & _
            " WHERE kode_kategori='" & grid2.TextMatrix(grid2.Row, 0) & "'", mydb, adOpenStatic
        If rs.EOF Then
            mydb.Execute "DELETE FROM T_kategori WHERE kode_kategori='" & grid2.TextMatrix(grid2.Row, 0) & "'"
            rs.Close
            Command2_Click
        Else
            MsgBox "Data kategori " & grid2.TextMatrix(grid2.Row, 1) & " tidak dapat dihapus karena terpakai !", vbOKOnly, "INFO"
            rs.Close
        End If
    
Else
    Text1.Text = grid2.TextMatrix(grid2.Row, 0)
    Text2.Text = Trim(grid2.TextMatrix(grid2.Row, 1))
    Text3.Text = Trim(grid2.TextMatrix(grid2.Row, 2))
    kondisi = 1
    
End If
head
grid
End Sub

Form Libur

Dim kondisi As String

Private Sub Command1_Click()
If kondisi = 0 Then
    rs.Open "SELECT tgl_libur FROM T_libur" & _
            " WHERE tgl_libur='" & Format(date1.Value, "MM/dd/yyyy") & "'", mydb, adOpenStatic

    If rs.EOF Then
        mydb.Execute "INSERT INTO T_libur VALUES('" & Format(date1.Value, "MM/dd/yyyy") & "','" & _
                                                  Text1.Text & "')"
        awal
    
    Else
        MsgBox "Tanggal " & date1.Value & " Sudah tersimpan sebagai hari libur !", vbOKOnly
        Text1.Text = ""
        Text1.SetFocus
    
    End If
    rs.Close
    grid
    head

Else
    mydb.Execute "UPDATE T_libur SET ket='" & Text1.Text & "'" & _
                 " WHERE tgl_libur='" & Format(date1.Value, "MM/dd/yyyy") & "'"
    grid
    head
    awal
    
End If
End Sub

Private Sub Command2_Click()
Call Buka(True)
Unload Me
End Sub

Private Sub Command3_Click()
Dim tanggal As Date
Dim hr As String
hr = "Minggu"

rs.Open "SELECT mingguakhir FROM T_opsi", mydb, adOpenStatic
tanggal = rs.Fields("mingguakhir") + 7

rs2.Open "SELECT tgl_libur FROM T_libur" & _
         " WHERE tgl_libur = '" & CDate(tanggal) & "'", mydb, adOpenStatic

If rs2.EOF Then
mydb.Execute "INSERT INTO T_libur VALUES('" & tanggal & "','" & _
                                              hr & "')"
End If
rs2.Close

While Year(tanggal) < Year(Date) + 1
tanggal = CDate(tanggal + 7)
rs2.Open "SELECT tgl_libur FROM T_libur" & _
         " WHERE tgl_libur = '" & CDate(tanggal) & "'", mydb, adOpenStatic

If rs2.EOF Then
mydb.Execute "INSERT INTO T_libur VALUES('" & tanggal & "','" & _
                                              hr & "')"
End If
rs2.Close
Wend

mydb.Execute "UPDATE T_opsi SET mingguakhir='" & tanggal & "'" & _
             " WHERE kode = '" & 1 & "'"

rs.Close

grid
head
awal
Command3.Enabled = False
End Sub

Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
BukaDB
grid
head
kondisi = 0

rs2.Open "SELECT mingguakhir FROM T_opsi", mydb, adOpenStatic

If Date >= rs2.Fields("mingguakhir") Then
    Command3.Enabled = True
Else
    Command3.Enabled = False
End If
rs2.Close
End Sub

Function head()
rs.Open "SELECT tgl_libur as LIBUR, ket as KETERANGAN FROM T_libur" & _
        " WHERE ket='" & hquhufhaihs & "'", mydb, adOpenStatic
Set grid1.Recordset = rs

With grid1
    .Row = 0
    .Col = 0
    .CellFontBold = True
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 1
    .CellFontBold = True
    .ColWidth(1) = 2000
    .CellAlignment = flexAlignCenterCenter
End With
rs.Close
End Function

Function grid()
rs.Open "SELECT * FROM T_libur" & _
        " ORDER BY tgl_libur", mydb, adOpenStatic
Set grid2.Recordset = rs

With grid2
    .Row = 0
    .Col = 1
    .ColWidth(1) = 2000
End With
rs.Close
End Function

Private Sub grid2_DblClick()
Dim jika As String
jika = MsgBox("Hapus Data ??", vbYesNo, "INFORMASI")
If jika = vbYes Then
    mydb.Execute "DELETE FROM T_libur WHERE tgl_libur='" & grid2.TextMatrix(grid2.Row, 0) & "'"
    awal
    
Else
    date1.Value = grid2.TextMatrix(grid2.Row, 0)
    Text1.Text = grid2.TextMatrix(grid2.Row, 1)
    date1.Enabled = False
    Text1.Enabled = True
    kondisi = 1
    
End If
head
grid

End Sub

Function awal()
date1.Value = Date
Text1.Text = ""
date1.Enabled = True
Text1.Enabled = True
kondisi = 0

End Function

Form Petugas
Dim kondisi As String

Private Sub Command1_Click()
If Text2.Text = "" Or Len(Text2.Text) < "4" Then
    MsgBox "Isikan Nama minimal 4 karakter !", vbOKOnly, "INFO"
    Text2.SetFocus
    Exit Sub
ElseIf Text3.Text = "" Or Len(Text3.Text) < "5" Then
    MsgBox "Alamat belum diisikan, atau terlalu pendek !", vbOKOnly, "INFO"
    Text3.SetFocus
    Exit Sub
ElseIf Text4.Text = "" Or Len(Text4.Text) < "6" Then
    MsgBox "Isikan Telepon  !", vbOKOnly, "INFO"
    Text4.SetFocus
    Exit Sub
ElseIf Combo1.Text <> "ADMIN" And Combo1.Text <> "PETUGAS" Then
    MsgBox "Pilih level user !", vbOKOnly, "INFO"
    Exit Sub
End If

Dim jk As String
If Option1.Value = True Then
    jk = "L"
ElseIf Option2.Value = True Then
    jk = "P"
End If

If kondisi = 0 Then
    rs.Open "SELECT kode_petugas FROM T_Petugas " & _
        " WHERE nama_petugas LIKE '" & Text2.Text & "'", mydb, adOpenStatic

    If rs.EOF Then
        mydb.Execute "INSERT INTO T_Petugas VALUES('" & Text1.Text & "','" & _
                                                Text2.Text & "','" & _
                                                jk & "','" & _
                                                Text3.Text & "','" & _
                                                Text4.Text & "')"
        Dim lv As String
        If Combo1.Text = "ADMIN" Then
            lv = "0"
        Else
            lv = "1"
        End If
        mydb.Execute "INSERT INTO T_user VALUES('" & Text1.Text & "','" & _
                                                 Text1.Text & "','" & _
                                                 Text1.Text & "'," & _
                                                 lv & ")"
                                                
    Else
        MsgBox "Sudah tersimpan data Petugas " & Text2.Text & " !", vbOKOnly, "INFO"
    
    End If
    rs.Close
    Command2_Click
    
Else
    mydb.Execute "UPDATE T_petugas SET alamat_petugas='" & Text3.Text & "'," & _
                 " telp='" & Text4.Text & "'" & _
                 " WHERE kode_petugas='" & Text1.Text & "'"
    Command2_Click
    
End If
End Sub

Private Sub Command2_Click()
K_Petugas
Option1.Enabled = True
Option2.Enabled = True
Text2.Enabled = True
Combo1.Enabled = True
Combo1.Text = ""
Text1.Text = no_petugas
Text2.Text = ""
Option1.Value = True
Text3.Text = ""
Text4.Text = ""
Text2.SetFocus
grid
kondisi = 0
End Sub

Private Sub Command3_Click()
Call Buka(True)
Unload Me
End Sub

Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
BukaDB
K_Petugas
Text1.Text = no_petugas
head
grid
kondisi = 0
Combo1.AddItem ("ADMIN")
Combo1.AddItem ("PETUGAS")
End Sub

Private Sub grid2_DblClick()
Dim jika As String
jika = MsgBox("Hapus Data ??", vbYesNo, "INFORMASI")
If jika = vbYes Then
    rs.Open "SELECT kode_petugas FROM T_transpinjam" & _
            " WHERE kode_petugas='" & grid2.TextMatrix(grid2.Row, 0) & "'", mydb, adOpenStatic
        If rs.EOF Then
            mydb.Execute "DELETE FROM T_petugas WHERE kode_petugas='" & grid2.TextMatrix(grid2.Row, 0) & "'"
            mydb.Execute "DELETE FROM T_user WHERE kode_petugas='" & grid2.TextMatrix(grid2.Row, 0) & "'"
            rs.Close
            Command2_Click
        Else
            MsgBox "Data petugas " & grid2.TextMatrix(grid2.Row, 1) & " tidak dapat dihapus karena terpakai !", vbOKOnly, "INFO"
            rs.Close
        End If
    
Else
    rs.Open "SELECT T_petugas.kode_petugas, nama_petugas, jns_kelamin, alamat_petugas, telp, lvl" & _
            " FROM T_petugas, T_user " & _
            " WHERE T_petugas.kode_petugas = T_user.kode_petugas " & _
            " AND T_petugas.kode_petugas='" & grid2.TextMatrix(grid2.Row, 0) & "'", mydb, adOpenStatic
            
    Text1.Text = grid2.TextMatrix(grid2.Row, 0)
    If lvl = "0" Then
        Combo1.Text = "ADMIN"
    Else
        Combo1.Text = "PETUGAS"
    End If
    Text2.Text = rs.Fields("nama_petugas")
    Text3.Text = rs.Fields("alamat_petugas")
    Text4.Text = rs.Fields("telp")
    If rs.Fields("jns_kelamin") = "L" Then
        Option1.Value = True
    Else
        Option2.Value = True
    End If
    kondisi = 1
    Text2.Enabled = False
    Combo1.Enabled = False
    Option1.Enabled = False
    Option2.Enabled = False
    rs.Close
    
End If
End Sub

Private Sub Text4_KeyPress(KeyAscii As Integer)
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then

Else
    Beep
    KeyAscii = 0
End If
End Sub

Function head()
With grid1
    .Row = 0
    .Col = 0
    .Text = "KODE"
    .CellFontBold = True
    .ColWidth(0) = 1500
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 1
    .Text = "NAMA"
    .CellFontBold = True
    .ColWidth(1) = 3200
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 2
    .Text = "TELEPON"
    .CellFontBold = True
    .ColWidth(2) = 1800
    .CellAlignment = flexAlignCenterCenter
End With
End Function

Function grid()
rs.Open "SELECT kode_petugas, nama_petugas, telp FROM T_petugas" & _
        " ORDER BY kode_petugas", mydb, adOpenStatic
        
Set grid2.Recordset = rs
With grid2
    .Row = 0
    .Col = 0
    .ColWidth(0) = 1500
    .Row = 0
    .Col = 1
    .ColWidth(1) = 3200
    .Row = 0
    .Col = 2
    .ColWidth(2) = 1800
End With
rs.Close
End Function

Form User & Password
Private Sub Command1_Click()
rs.Open "SELECT * FROM T_user WHERE username='" & Text2.Text & "'", mydb, adOpenStatic
    If Not rs.EOF Then
        MsgBox "Username Sudah Terpakai !", vbOKOnly, "INFO"
        Text2.Text = ""
        Text2.SetFocus
        rs.Close
        Exit Sub
    End If
rs.Close
If Text3.Text <> Text4.Text Then
    MsgBox "Password tidak sama !", vbOKOnly, "INFO"
    Text3.Text = ""
    Text4.Text = ""
    Text3.SetFocus
    Exit Sub
End If
If Len(Text2.Text) < 3 Then
    MsgBox "Isikan User minimal 3 karakter !", vbOKOnly, "INFO"
    Text2.SetFocus
    Text2.Text = ""
    Exit Sub
End If
If Len(Text3.Text) < 3 Then
    MsgBox "Isikan Password minimal 3 karakter !", vbOKOnly, "INFO"
    Text3.Text = ""
    Text4.Text = ""
    Text3.SetFocus
    Exit Sub
End If

mydb.Execute "UPDATE T_user SET username='" & Text2.Text & "'," & _
             " password = '" & Text3.Text & "' WHERE kode_petugas='" & Text1.Text & "'"

F_Menu.StatusBar1.Panels.Item(2) = Text2.Text
rs2.Open "SELECT lvl FROM T_user WHERE username='" & Text2.Text & "'", mydb, adOpenStatic
    If rs2.Fields("lvl") = "0" Then
        F_Menu.StatusBar1.Panels.Item(4) = "Admin"
        Akses_Admin
    Else
        F_Menu.StatusBar1.Panels.Item(4) = "Petugas"
        Akses_Pegawai
    End If
rs2.Close
F_Menu.Show
Unload F_UBaru

End Sub

Private Sub Form_Load()
BukaDB
End Sub

Form Pengaturan
Private Sub Command1_Click()
If Command1.Caption = "&UPDATE" Then
    Text1.Enabled = True
    Text2.Enabled = True
    Text3.Enabled = True
    Command1.Caption = "&SIMPAN"
    
ElseIf Command1.Caption = "&SIMPAN" Then
    If Text1.Text < 100 Then
        MsgBox "Denda terlalu kecil, inputkan diatas 100 !", vbOKOnly, "INFO"
        Text1.Text = ""
        Text1.SetFocus
        Exit Sub
    End If
    If Text2.Text < 2 Then
        MsgBox "Batas Peminjaman Minimal 2 Hari !", vbOKOnly, "INFO"
        Text2.Text = ""
        Text2.SetFocus
        Exit Sub
    End If
    If Text3.Text < 2 Then
        MsgBox "Batas Perpanjangan Minimal 2 Hari !", vbOKOnly, "INFO"
        Text3.Text = ""
        Text3.SetFocus
        Exit Sub
    End If

    rs.Open "SELECT * FROM T_opsi", mydb, adOpenStatic
    If rs.EOF Then
        mydb.Execute "INSERT INTO T_opsi VALUES('" & 1 & "'," & _
                                                 Text1.Text & "," & _
                                                 Text2.Text & ")"
    Else
        mydb.Execute "UPDATE T_opsi SET denda=" & Text1.Text & "," & _
                 " telat=" & Text2.Text & ", perpanjang=" & Text3.Text & ""
    End If
    rs.Close
    Command2_Click
End If

End Sub

Private Sub Command2_Click()
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Command1.Caption = "&UPDATE"
rs.Open "SELECT * FROM T_opsi WHERE kode='" & 1 & "'", mydb, adOpenStatic
    If rs.EOF Then
    Text1.Text = "0"
    Text2.Text = "0"
    Text3.Text = "0"
    
    Else
    Text1.Text = rs.Fields("denda")
    Text2.Text = rs.Fields("telat")
    Text3.Text = rs.Fields("perpanjang")
    End If
rs.Close
End Sub

Private Sub Command3_Click()
Call Buka(True)
Unload Me
End Sub

Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
BukaDB

Command2_Click
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then

Else
    Beep
    KeyAscii = 0
End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then

Else
    Beep
    KeyAscii = 0
End If
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then

Else
    Beep
    KeyAscii = 0
End If
End Sub

Private Sub Timer1_Timer()
If Time > "07:00:00" And Time < "16:00:00" Then
    Command1.Enabled = False
Else
    Command1.Enabled = True
End If
End Sub

Form Peminjaman
Function bersih1()
K_Pinjam
Text3.Text = no_pinjam
Text1.Text = ""
Text2.Text = ""
Text1.Enabled = True
Text5.Enabled = False
Text1.SetFocus
Command4.Enabled = False
Command2.Enabled = False

End Function

Function bersih2()
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text5.SetFocus
Command1.Enabled = False

End Function

Function grid()
With grid2
    .Row = 0
    .Col = 0
    .Text = "no_pinjam"
    .CellFontBold = True
    .ColWidth(0) = 1400
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 1
    .Text = "tgl_pinjam"
    .CellFontBold = True
    .ColWidth(1) = 1500
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 2
    .Text = "inventaris"
    .CellFontBold = True
    .ColWidth(2) = 3000
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 3
    .Text = "judul"
    .CellFontBold = True
    .ColWidth(3) = 1400
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 4
    .Text = "kembali"
    .CellFontBold = True
    .ColWidth(3) = 1400
    .CellAlignment = flexAlignCenterCenter
End With

End Function

Function gridd()
rs.Open "SELECT T_trans.no_pinjam as 'no. pinjam',tgl_pinjam as 'tgl pinjam', " & _
        " T_transpinjam.no_inventaris as inventaris, judul," & _
        " (tgl_pinjam + telat + T_transpinjam.perpanjang + (select count(*) from T_libur where tgl_libur > tgl_pinjam and tgl_libur<= (tgl_pinjam + telat+ 1) )) as kembali" & _
        " FROM T_buku, T_trans, T_transpinjam, T_inventaris, T_opsi" & _
        " WHERE (T_buku.kode_buku = T_inventaris.kode_buku) " & _
        " AND (T_trans.no_pinjam = T_transpinjam.no_pinjam) " & _
        " AND (T_transpinjam.no_inventaris = T_inventaris.no_inventaris) " & _
        " AND no_anggota='" & Text1.Text & "'" & _
        " AND T_transpinjam.status_buku =" & 0 & "" & _
        " ORDER BY T_trans.no_pinjam", mydb, adOpenStatic

Set grid2.Recordset = rs
With grid2
    .Row = 0
    .Col = 0
    .CellFontBold = True
    .ColWidth(0) = 1200
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 1
    .CellFontBold = True
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 2
    .CellFontBold = True
    .ColWidth(2) = 1200
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 3
    .CellFontBold = True
    .ColWidth(3) = 2700
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 4
    .CellFontBold = True
    .CellAlignment = flexAlignCenterCenter
End With
rs.Close

End Function

Private Sub Command1_Click()
Dim rs9 As New ADODB.Recordset
rs.Open "select*from T_inventaris where no_inventaris='" & Text5.Text & "'" & _
        " And status_buku = " & 1 & "", mydb, adOpenStatic
    If rs.EOF Then
    MsgBox "Buku Sudah Keluar atau Rusak !", vbOKOnly, "INFO"
    rs.Close
    Exit Sub
    End If
rs.Close

rs.Open "SELECT COUNT(no_inventaris) as jumlpinjam " & _
        " FROM T_trans, T_transpinjam" & _
        " WHERE (T_trans.no_pinjam = T_transpinjam.no_pinjam)" & _
        " AND no_anggota='" & Text1.Text & "'" & _
        " AND status_buku=" & 0 & "", mydb, adOpenStatic

If Not rs.EOF Then
    If rs.Fields("jumlpinjam") > 1 Then
        MsgBox "PEMINJAMAN BUKU SUDAH MAKSIMUM(2) !", vbOKOnly, "INFO"
        Call bersih2
        rs.Close
        Exit Sub
    End If
    rs.Close
Else
    rs.Close
End If

rs.Open "SELECT kode_petugas FROM T_user WHERE username = '" & F_Menu.StatusBar1.Panels.Item(2) & "'", mydb, adOpenStatic
mydb.Execute "INSERT INTO T_transpinjam (no_pinjam, no_inventaris, kode_petugas, status_buku, perpanjang) VALUES('" & Text3.Text & "','" & _
                                                    Text5.Text & "','" & _
                                                    rs.Fields("kode_petugas") & "'," & _
                                                    0 & "," & _
                                                    0 & ")"
rs.Close
mydb.Execute "UPDATE T_inventaris SET status_buku=" & 2 & "" & _
             " WHERE no_inventaris='" & Text5.Text & "'"
             
Call bersih2
Call gridd
Command2.Enabled = True

End Sub

Private Sub Command2_Click()
Call bersih2
Call bersih1
Call gridd
End Sub

Private Sub Command3_Click()
rs.Open "SELECT no_pinjam FROM T_transpinjam" & _
        " WHERE no_pinjam='" & Text3.Text & "'", mydb, adOpenStatic

If rs.EOF Then
    mydb.Execute "DELETE FROM T_trans WHERE no_pinjam='" & Text3.Text & "'"
    
End If
rs.Close
Call Buka(True)
Unload Me
End Sub

Private Sub Command4_Click()
konf = MsgBox("Batalkan Traksaksi Peminjaman Ini ?", vbYesNo, "KONFIRM")
    If konf = vbYes Then
        mydb.Execute "DELETE FROM T_trans " & _
                     " WHERE no_pinjam='" & Text3.Text & "'"
        rs.Open "SELECT no_inventaris FROM T_transpinjam" & _
                " WHERE no_pinjam='" & Text3.Text & "'" & _
                " ORDER BY no_inventaris", mydb, adOpenStatic
        
        While Not rs.EOF
            mydb.Execute "UPDATE T_inventaris set status_buku=" & 1 & "" & _
                         " where no_inventaris='" & rs.Fields("no_inventaris") & "'"
            rs.MoveNext
        Wend
        rs.Close
        
        mydb.Execute "DELETE FROM T_transpinjam " & _
                     " WHERE no_pinjam='" & Text3.Text & "'"
        Call bersih2
        Call bersih1
        Call gridd
        
    End If
End Sub

Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
BukaDB
K_Pinjam
Text3.Text = no_pinjam
Text4.Text = Format(Date, "dd/mm/yyyy")
gridd
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    rs.Open "SELECT no_anggota, nama FROM T_Anggota " & _
            " WHERE no_anggota = '" & Text1.Text & "'", mydb, adOpenStatic
    If rs.EOF Then
        MsgBox "Nomor Anggota tidak terdaftar !", vbOKOnly, "INFO"
        Text1.Text = ""
        rs.Close
        Exit Sub
        
    Else
        K_Pinjam
        Text2.Text = rs.Fields("nama")
        Text3.Text = no_pinjam
        Text1.Enabled = False
        Text5.Enabled = True
        Command4.Enabled = True
        Text5.SetFocus
        rs.Close
        mydb.Execute "INSERT INTO T_trans VALUES('" & Text3.Text & "','" & _
                                                      Format(Date, "MM/dd/yyyy") & "','" & _
                                                      Text1.Text & "')"
        Call gridd
        
    End If
    
End If
End Sub

Private Sub Text5_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    'cek peminjaman apakah 2 ato kurang dari 2----------------------------
    rs.Open "SELECT COUNT(no_inventaris) as jumlpinjam " & _
        " FROM T_trans, T_transpinjam" & _
        " WHERE (T_trans.no_pinjam = T_transpinjam.no_pinjam)" & _
        " AND no_anggota='" & Text1.Text & "'" & _
        " AND status_buku=" & 0 & "", mydb, adOpenStatic

    If Not rs.EOF Then
    If rs.Fields("jumlpinjam") > 1 Then
        MsgBox "PEMINJAMAN BUKU SUDAH MAKSIMUM(2) !", vbOKOnly, "INFO"
        Call bersih2
        rs.Close
        Exit Sub
    End If
    rs.Close
    Else
    rs.Close
    End If
    '----------------------------------------------------------------------

    rs.Open "SELECT T_buku.kode_buku, judul, no_inventaris " & _
            " FROM T_inventaris, T_buku" & _
            " WHERE T_inventaris.kode_buku = T_buku.kode_buku" & _
            " AND status_buku = " & 1 & "" & _
            " AND no_inventaris='" & Text5.Text & "'", mydb, adOpenStatic
    
    If rs.EOF Then
        MsgBox "Nomor Inventaris ini sedang keluar / rusak !", vbOKOnly, "INFO"
        Text5.Text = ""
        Text5.SetFocus
        rs.Close
        Exit Sub
        
    Else
        Text6.Text = rs.Fields("kode_buku")
        Text7.Text = rs.Fields("judul")
        Command1.Enabled = True
        rs.Close
        Call gridd
    End If
    
ElseIf KeyAscii = vbKeyBack Then
    Call bersih2
    
End If
End Sub

Form Pengembalian
Function grid()
rs.Open "SELECT T_trans.no_pinjam as 'no. pinjam',tgl_pinjam as 'tgl pinjam', " & _
        " T_transpinjam.no_inventaris as inventaris, judul," & _
        " (tgl_pinjam + T_transpinjam.perpanjang + telat + (select count(*) from T_libur where tgl_libur > tgl_pinjam and tgl_libur<= (tgl_pinjam + telat+ 1) )) as kembali" & _
        " FROM T_buku, T_trans, T_transpinjam, T_inventaris, T_opsi" & _
        " WHERE (T_buku.kode_buku = T_inventaris.kode_buku) " & _
        " AND (T_trans.no_pinjam = T_transpinjam.no_pinjam) " & _
        " AND (T_transpinjam.no_inventaris = T_inventaris.no_inventaris) " & _
        " AND no_anggota='" & Text1.Text & "'" & _
        " AND T_transpinjam.status_buku =" & 0 & "" & _
        " ORDER BY T_trans.no_pinjam", mydb, adOpenStatic

Set grid1.Recordset = rs
If rs.EOF Then
    grid1.Enabled = False
Else
    grid1.Enabled = True
End If

With grid1
    .ColWidth(0) = 1200
    .ColWidth(2) = 1200
    .ColWidth(3) = 2700
End With
rs.Close
End Function

Function gridhead()
rs.Open "SELECT T_trans.no_pinjam as 'no. pinjam',tgl_pinjam as 'tgl pinjam', " & _
        " T_transpinjam.no_inventaris as inventaris, judul," & _
        " (tgl_pinjam + 2) as kembali" & _
        " FROM T_buku, T_trans, T_transpinjam, T_inventaris" & _
        " WHERE (T_buku.kode_buku = T_inventaris.kode_buku) " & _
        " AND (T_trans.no_pinjam = T_transpinjam.no_pinjam) " & _
        " AND (T_transpinjam.no_inventaris = T_inventaris.no_inventaris) " & _
        " AND T_transpinjam.status_buku =" & 99 & "" & _
        " ORDER BY T_trans.no_pinjam", mydb, adOpenStatic

Set grid2.Recordset = rs
With grid2
    .Row = 0
    .Col = 0
    .CellFontBold = True
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 1
    .CellFontBold = True
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 2
    .CellFontBold = True
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 3
    .CellFontBold = True
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 4
    .CellFontBold = True
    .CellAlignment = flexAlignCenterCenter
    .ColWidth(0) = 1200
    .ColWidth(2) = 1200
    .ColWidth(3) = 2700
End With
rs.Close
End Function
Private Sub Command2_Click()
If Text5.Text > "0" Then
sql = "SELECT DISTINCT T_transpinjam.no_pinjam, T_anggota.no_anggota, T_trans.tgl_pinjam, " & _
          " T_transpinjam.no_inventaris, T_buku.judul, T_transkembali.tgl_kembali, T_transkembali.denda" & _
          " From T_trans, T_transpinjam, T_transkembali, T_buku, T_inventaris, T_anggota" & _
          " Where T_trans.no_pinjam = T_transpinjam.no_pinjam" & _
          " AND T_trans.no_pinjam = T_transkembali.no_pinjam" & _
          " AND T_inventaris.kode_buku = T_buku.kode_buku" & _
          " AND T_inventaris.no_inventaris = T_transpinjam.no_inventaris" & _
          " AND T_inventaris.no_inventaris = T_transkembali.no_inventaris" & _
          " AND T_anggota.no_anggota = T_trans.no_anggota" & _
          " AND T_transkembali.denda > 0" & _
          " AND tgl_kembali = '" & Format(Date, "MM/dd/yyyy") & "'" & _
          " AND T_anggota.no_anggota = '" & Text1.Text & "'" & _
          " ORDER BY tgl_pinjam"
    
    Set rsb = mydb.Execute(sql)
    If Not rsb.EOF Then
        
    data.Commands(12).CommandText = sql
    denda_cetak.Sections("Section4").Controls("nomor").Caption = Text1.Text
    denda_cetak.Sections("Section4").Controls("nama").Caption = Text2.Text
    denda_cetak.Refresh
    denda_cetak.Show
    End If
End If
    
Text1.Text = ""
Text2.Text = ""
Text5.Text = ""
Text1.Enabled = True
Text1.SetFocus

Call grid
Command2.Enabled = False

End Sub

Private Sub Command3_Click()
Call Buka(True)
Unload Me
End Sub

Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
BukaDB
Text4.Text = Format(Date, "dd/mm/yyyy")
grid
gridhead
End Sub

Private Sub grid1_DblClick()
rs.Open "select*from T_transkembali where no_pinjam='" & grid1.TextMatrix(grid1.Row, 0) & "'", mydb, adOpenStatic
    If Not rs.EOF Then
        MsgBox "Buku Terpinjam sudah dikembalikan", vbOKOnly, "INFO"
        rs.Close
        Text1.Text = ""
        Text2.Text = ""
        Text5.Text = ""
        Text1.Enabled = True
        Text1.SetFocus
        Call grid
        Command2.Enabled = False
        Exit Sub
    End If

rs.Close
Me.Enabled = False
Dim telat As String
rs.Open "SELECT tgl_pinjam, tgl_pinjam + telat + T_transpinjam.perpanjang + (select count(*) from T_libur where tgl_libur > tgl_pinjam and tgl_libur<= (tgl_pinjam + telat+ 1)) as tglakhir " & _
        " FROM T_trans, T_transpinjam, T_opsi" & _
        " WHERE T_trans.no_pinjam = T_transpinjam.no_pinjam" & _
        " AND no_anggota='" & Text1.Text & "'" & _
        " AND T_trans.no_pinjam='" & grid1.TextMatrix(grid1.Row, 0) & "'" & _
        " AND no_inventaris='" & grid1.TextMatrix(grid1.Row, 2) & "'", mydb, adOpenStatic

If rs.EOF Then
    rs.Close
    Me.Enabled = True
    Exit Sub
End If

Dim tg, tg1 As String
tg = Format(grid1.TextMatrix(grid1.Row, 4), "yyyy/m/d")
tg1 = Format(Date, "yyyy/m/d")
tg1 = tg1
rs2.Open "SELECT COUNT(tgl_libur)as ttl_lbr FROM T_libur" & _
         " WHERE tgl_libur >= '" & tg & "'" & _
         " AND tgl_libur <= '" & tg1 & "'", mydb, adOpenStatic

If CDate(Format(rs.Fields("tglakhir"), "d/M/yyyy")) < Format(Date, "d/M/yyyy") Then
    telat = (Date - CDate(grid1.TextMatrix(grid1.Row, 4)) - rs2.Fields("ttl_lbr"))
    
Else
    telat = "0"
    
End If
rs.Close
rs2.Close

nomor = grid1.TextMatrix(grid1.Row, 0)
T_skemb.Text1.Text = grid1.TextMatrix(grid1.Row, 2)
T_skemb.Text2.Text = grid1.TextMatrix(grid1.Row, 3)
T_skemb.Text3.Text = telat
T_skemb.Show
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    rs.Open "SELECT no_anggota, nama FROM T_Anggota " & _
            " WHERE no_anggota = '" & Text1.Text & "'", mydb, adOpenStatic
    If rs.EOF Then
        MsgBox "Nomor Anggota tidak terdaftar !", vbOKOnly, "INFO"
        Text1.Text = ""
        rs.Close
        grid1.Enabled = False
        Exit Sub
        
    Else
        rs2.Open "SELECT T_trans.no_pinjam FROM T_transpinjam, T_trans" & _
                 " WHERE status_buku=" & 0 & "" & _
                 " AND no_anggota='" & Text1.Text & "'", mydb, adOpenStatic
                 
            If rs2.EOF Then
                MsgBox "Anggota " & rs.Fields("nama") & " Tidak memiliki Pinjaman !", vbOKOnly, "INFO"
                Text1.Text = ""
                rs.Close
                rs2.Close
                Exit Sub
            End If
        rs2.Close
        
        Text2.Text = rs.Fields("nama")
        Text1.Enabled = False
        Command2.Enabled = True
        rs.Close
        Call grid
        
    End If
End If
End Sub

Form Pengembalian

Dim rsgrid As New ADODB.Recordset
Dim ask As String

Function grid()
rsgrid.Open "SELECT T_trans.no_pinjam as 'no. pinjam',tgl_pinjam as 'tgl pinjam', " & _
        " T_transpinjam.no_inventaris as inventaris, judul," & _
        " (tgl_pinjam + T_transpinjam.perpanjang + telat + (select count(*) from T_libur where tgl_libur > tgl_pinjam and tgl_libur<= (tgl_pinjam + telat+ 1) )) as kembali" & _
        " FROM T_buku, T_trans, T_transpinjam, T_inventaris, T_opsi" & _
        " WHERE (T_buku.kode_buku = T_inventaris.kode_buku) " & _
        " AND (T_trans.no_pinjam = T_transpinjam.no_pinjam) " & _
        " AND (T_transpinjam.no_inventaris = T_inventaris.no_inventaris) " & _
        " AND no_anggota='" & Text1.Text & "'" & _
        " AND T_transpinjam.status_buku =" & 0 & "" & _
        " ORDER BY T_trans.no_pinjam", mydb, adOpenStatic

Set grid1.Recordset = rsgrid
With grid1
    .ColWidth(0) = 1200
    .ColWidth(2) = 1200
    .ColWidth(3) = 2700
End With
rsgrid.Close
End Function

Function gridd()
rsgrid.Open "SELECT T_trans.no_pinjam as 'no. pinjam',tgl_pinjam as 'tgl pinjam', " & _
        " T_transpinjam.no_inventaris as inventaris, judul," & _
        " (tgl_pinjam + T_transpinjam.perpanjang + telat) as kembali" & _
        " FROM T_buku, T_trans, T_transpinjam, T_inventaris, T_opsi" & _
        " WHERE (T_buku.kode_buku = T_inventaris.kode_buku) " & _
        " AND (T_trans.no_pinjam = T_transpinjam.no_pinjam) " & _
        " AND (T_transpinjam.no_inventaris = T_inventaris.no_inventaris) " & _
        " AND no_anggota='" & Text1.Text & "'" & _
        " AND T_transpinjam.status_buku =" & 9 & "" & _
        " ORDER BY T_trans.no_pinjam", mydb, adOpenStatic

Set grid2.Recordset = rsgrid
With grid2
    .Row = 0
    .Col = 0
    .CellFontBold = True
    .ColWidth(0) = 1200
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 1
    .CellFontBold = True
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 2
    .CellFontBold = True
    .ColWidth(2) = 1200
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 3
    .CellFontBold = True
    .ColWidth(3) = 2700
    .CellAlignment = flexAlignCenterCenter
    .Row = 0
    .Col = 4
    .CellFontBold = True
    .CellAlignment = flexAlignCenterCenter
End With
rsgrid.Close
End Function

Private Sub Command2_Click()

End Sub

Private Sub Command3_Click()
Call Buka(True)
Unload Me
End Sub

Private Sub Command4_Click()
Text1.Text = ""
Text2.Text = ""
Text1.Enabled = True
Text1.SetFocus
Text3.Text = "0"
grid
End Sub

Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
BukaDB
Text4.Text = Date
gridd
grid
End Sub

Private Sub grid1_DblClick()
rs.Open "SELECT tgl_pinjam, T_opsi.perpanjang,(tgl_pinjam + T_transpinjam.perpanjang + telat + (select count(*) from T_libur where tgl_libur >= tgl_pinjam and tgl_libur<= (tgl_pinjam + telat+ 1))) as kembali" & _
        " FROM T_trans, T_transpinjam, T_opsi" & _
        " WHERE (T_trans.no_pinjam = T_transpinjam.no_pinjam) " & _
        " AND no_anggota='" & Text1.Text & "'" & _
        " AND T_transpinjam.status_buku =" & 0 & "" & _
        " AND T_transpinjam.perpanjang = " & 0 & "" & _
        " AND no_inventaris='" & grid1.TextMatrix(grid1.Row, 2) & "'" & _
        " ORDER BY T_trans.no_pinjam", mydb, adOpenStatic

If rs.EOF Then
    MsgBox "Perpanjangan buku ini sudah pernah dilakukan !", vbOKOnly, "INFORMASI"
    rs.Close
    Exit Sub
End If

If CDate(rs.Fields("kembali") + rs.Fields("perpanjang")) <= Date Then
    MsgBox "TERLAMBAT, TIDAK BISA DIPERPANJANG !", vbOKOnly, "INFO"

ElseIf rs.Fields("tgl_pinjam") = Date Then
    MsgBox "Buku Terpinjam Hari ini Tidak dapat Diperpanjang !", vbOKOnly, "INFO"

'ElseIf rs.Fields("kembali") < Date Then
    'terlambat, boleh perpanjang asal bayar denda dulu
    
Else
    ask = MsgBox("Perpanjang Buku No " & grid1.TextMatrix(grid1.Row, 2) & " ??", vbOKCancel, "INFORMASI")
        If ask = vbCancel Then
            rs.Close
            Exit Sub
        End If
        
        rsopsi.Open "SELECT * FROM T_opsi", mydb, adOpenStatic
        If rs.Fields("kembali") < Date Then
            
            Dim tg, tg1 As String
            tg = Format(rs.Fields("tgl_pinjam"), "yyyy/m/d")
            tg1 = Format(Date, "yyyy/m/d")
            tg1 = tg1
            rs2.Open "SELECT COUNT(tgl_libur)as ttl_lbr FROM T_libur" & _
                     " WHERE tgl_libur >= '" & tg & "'" & _
                     " AND tgl_libur <= '" & tg1 & "'", mydb, adOpenStatic

            If CDate(Format(rs.Fields("kembali"), "d/M/yyyy")) < Format(Date, "d/M/yyyy") Then
                telat = (Date - CDate(grid1.TextMatrix(grid1.Row, 4)))
    
            Else
                telat = "0"
    
            End If

            Text3.Text = Text3.Text + ((Date - CDate(rs.Fields("kembali"))) * rsopsi.Fields("denda"))
            rs2.Close
        End If
        
        mydb.Execute "UPDATE T_transpinjam SET perpanjang=" & rsopsi.Fields("perpanjang") & "" & _
                 " WHERE no_pinjam = '" & grid1.TextMatrix(grid1.Row, 0) & "'" & _
                 " AND no_inventaris = '" & grid1.TextMatrix(grid1.Row, 2) & "'"
        rsopsi.Close
        grid
End If
rs.Close
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    rs.Open "SELECT no_anggota, nama FROM T_Anggota " & _
            " WHERE no_anggota = '" & Text1.Text & "'", mydb, adOpenStatic
    If rs.EOF Then
        MsgBox "Nomor Anggota tidak terdaftar !", vbOKOnly, "INFO"
        Text1.Text = ""
        rs.Close
        Exit Sub
        
    Else
        rs2.Open "SELECT no_inventaris FROM T_trans, T_transpinjam" & _
            " WHERE T_trans.no_pinjam = T_transpinjam.no_pinjam" & _
            " AND no_anggota = '" & Text1.Text & "'" & _
            " AND status_buku = " & 0 & "", mydb, adOpenStatic
            
        If rs2.EOF Then
            MsgBox "Anggota Ini tidak memiliki pinjaman !", vbOKOnly, "INFO"
            rs2.Close
            rs.Close
            Command4_Click
            grid1.Enabled = False
            Exit Sub
        Else
            grid1.Enabled = True
            rs2.Close
        End If

        K_Pinjam
        Text2.Text = rs.Fields("nama")
        Text1.Enabled = False
        Command4.Enabled = True
        rs.Close
        Call grid
        
    End If
    
End If
End Sub

Form S_Kembalian
Private Sub Command1_Click()
Dim denda As Double
Dim status As Integer
rs.Open "SELECT denda_hilang, denda_rusak" & _
        " FROM T_buku, T_inventaris" & _
        " WHERE T_buku.kode_buku = T_inventaris.kode_buku" & _
        " AND T_inventaris.no_inventaris='" & Text1.Text & "'", mydb, adOpenStatic

If Combo1.Text = "ada" Then
    denda = "0"
    status = 1
    
ElseIf Combo1.Text = "rusak" Then
    denda = rs.Fields("denda_rusak")
    status = 3
    
ElseIf Combo1.Text = "hilang" Then
    denda = rs.Fields("denda_hilang")
    status = 4
    
End If

rsopsi.Open "SELECT kode_petugas, denda FROM T_user, T_opsi" & _
            " WHERE username = '" & F_Menu.StatusBar1.Panels.Item(2) & "'", mydb, adOpenStatic

denda = denda + (Val(Text3.Text) * rsopsi.Fields("denda"))

mydb.Execute "UPDATE T_inventaris SET status_buku=" & status & "" & _
             " WHERE no_inventaris='" & Text1.Text & "'"
             
mydb.Execute "UPDATE T_transpinjam SET status_buku=" & status & "" & _
             " WHERE no_pinjam='" & nomor & "'" & _
             " AND no_inventaris='" & Text1.Text & "'"

mydb.Execute "INSERT INTO T_transkembali VALUES('" & nomor & "','" & _
                                                    Format(Date, "MM/dd/yyyy") & "','" & _
                                                    Text1.Text & "','" & _
                                                    rsopsi.Fields("kode_petugas") & "'," & _
                                                    denda & ")"
rsopsi.Close

If T_Pengembalian.Text5.Text = "0" Or T_Pengembalian.Text5.Text = "" Then
    T_Pengembalian.Text5.Text = denda

Else
    T_Pengembalian.Text5.Text = Val(T_Pengembalian.Text5.Text) + denda

End If
rs.Close

T_Pengembalian.Enabled = True
T_Pengembalian.grid
Unload Me
End Sub

Private Sub Command2_Click()
T_Pengembalian.Enabled = True
Unload Me
End Sub

Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
BukaDB
End Sub

Akses
Function Akses_Admin()
F_Menu.input.Visible = True
F_Menu.anggotabaru.Visible = True
F_Menu.transaksi.Visible = False
F_Menu.laporan.Visible = True
F_Menu.pengaturan.Visible = True
End Function

Function Akses_Pegawai()
F_Menu.input.Visible = False
F_Menu.anggotabaru.Visible = False
F_Menu.transaksi.Visible = True
F_Menu.laporan.Visible = False
F_Menu.pengaturan.Visible = False
End Function

Function Buka(kondisi As Boolean)
F_Menu.menu.Enabled = (kondisi)
F_Menu.input.Enabled = (kondisi)
F_Menu.anggotabaru.Enabled = (kondisi)
F_Menu.transaksi.Enabled = (kondisi)
F_Menu.laporan.Enabled = (kondisi)
F_Menu.gantipass.Enabled = (kondisi)
F_Menu.pengaturan.Enabled = (kondisi)
End Function

Auto Kode
Global rskode As New ADODB.Recordset

Global kategori As String
Global no_inven As String

Global no_anggota As String
Global no_kategori As String
Global no_petugas As String
Global no_buku As String
Global no_masuk As String

Global no_pinjam As String

Global nomor As String

Function K_Anggota()
Dim kd As String
Dim no As String
Dim nol As String

rskode.Open "select no_anggota, anggota from T_Anggota,T_anggota_dt " & _
            " Where T_Anggota.status_anggota=T_anggota_dt.status_anggota" & _
            " and anggota = '" & F_Anggota.Combo1.Text & "'" & _
            " order by [no_anggota]", mydb, adOpenStatic
    
If rskode.EOF Then
    no_anggota = Left(F_Anggota.Combo1.Text, 1) + Right(Format(Date, "MM/dd/yyyy"), 2) + "01"
    
Else
    rskode.MoveLast
    If Mid(rskode.Fields("no_anggota"), 2, 2) <> Right(Format(Date, "MM/dd/yyyy"), 2) Then
        no_anggota = Left(F_Anggota.Combo1.Text, 1) + Right(Format(Date, "MM/dd/yyyy"), 2) + "01"
        
    Else
    no = Right(rskode.Fields("no_anggota"), 2) + 1
        If (no < 10) Then
        nol = "0"
        Else
        nol = ""
        End If
    no_anggota = Left(F_Anggota.Combo1.Text, 1) + Right(Format(Date, "MM/dd/yyyy"), 2) + nol + no
    End If
End If
rskode.Close
End Function

Function K_kategori()
Dim kd As String
Dim no As String
Dim nol As String
kd = "K"

rskode.Open "select kode_kategori from T_kategori" & _
            " order by [kode_kategori]", mydb, adOpenStatic
    
If rskode.EOF Then
    no_kategori = kd + "01"
    rskode.Close
    
Else
    rskode.MoveLast
    no = Right(rskode.Fields("kode_kategori"), 2) + 1
        If (no < 10) Then
        nol = "0"
        Else
        nol = ""
        End If
    no_kategori = kd + nol + no
    rskode.Close
    
End If
End Function

Function K_Petugas()
Dim kd As String
Dim no As String
Dim nol As String
kd = "P"

rskode.Open "select kode_petugas from T_petugas" & _
            " order by [kode_petugas]", mydb, adOpenStatic
    
If rskode.EOF Then
    no_petugas = kd + Right(Format(Date, "MM/dd/yyyy"), 2) + "001"
    
Else
    rskode.MoveLast
    If Mid(rskode.Fields("kode_petugas"), 2, 2) <> Right(Format(Date, "MM/dd/yyyy"), 2) Then
        no_petugas = kd + Right(Format(Date, "MM/dd/yyyy"), 2) + "001"
        
    Else
        no = Right(rskode.Fields("kode_petugas"), 3) + 1
            If (no < 10) Then
                nol = "00"
            ElseIf (no < 100) Then
                nol = "0"
            Else
                nol = ""
            End If
        no_petugas = kd + Right(Format(Date, "MM/dd/yyyy"), 2) + nol + no
    End If
End If
rskode.Close
End Function

Function K_Buku()
Dim kd As String
Dim no As String
Dim nol As String

rskode.Open "select kode_buku, T_kategori.kode_kategori from T_buku, T_Kategori " & _
            " Where T_buku.kode_kategori = T_Kategori.kode_kategori" & _
            " and nama_kategori = '" & F_Buku.Combo1.Text & "'" & _
            " order by [kode_buku]", mydb, adOpenStatic
    
If rskode.EOF Then
    no_buku = Right(Format(Date, "MM/dd/yyyy"), 2) + kategori + "001"
    
Else
    rskode.MoveLast
    If Left(rskode.Fields("kode_buku"), 2) <> Right(Format(Date, "MM/dd/yyyy"), 2) Then
        no_buku = Right(Format(Date, "MM/dd/yyyy"), 2) + kategori + "001"
        
    Else
    no = Right(rskode.Fields("kode_buku"), 3) + 1
        If (no < 10) Then
            nol = "00"
        ElseIf (no < 100) Then
            nol = "0"
        Else
            nol = ""
        End If
    no_buku = Right(Format(Date, "MM/dd/yyyy"), 2) + kategori + nol + no
    End If
End If
rskode.Close
End Function

Function K_masuk()
Dim kd As String
Dim no As String
Dim nol As String
Dim tg As String

rskode.Open "select no_masuk from T_masuk" & _
        " order by [no_masuk]", mydb, adOpenStatic
        
    If rskode.EOF Then
    tg = Right(Format(Date, "MM/dd/yyyy"), 2) + Left(Format(Date, "MM/dd/yyyy"), 2) + Mid(Format(Date, "MM/dd/yyyy"), 4, 2)
    kd = tg + "01"
    
    Else
    rskode.MoveLast
            
            If Left(rskode.Fields("no_masuk"), 6) <> Right(Format(Date, "MM/dd/yyyy"), 2) + Left(Format(Date, "MM/dd/yyyy"), 2) + Mid(Format(Date, "MM/dd/yyyy"), 4, 2) Then
            tg = Right(Format(Date, "MM/dd/yyyy"), 2) + Left(Format(Date, "MM/dd/yyyy"), 2) + Mid(Format(Date, "MM/dd/yyyy"), 4, 2)
            kd = tg + "01"
            
            Else
            
            no = Right(rskode.Fields("no_masuk"), 2) + 1
            If (no < 10) Then
            tg = Right(Format(Date, "MM/dd/yyyy"), 2) + Left(Format(Date, "MM/dd/yyyy"), 2) + Mid(Format(Date, "MM/dd/yyyy"), 4, 2)
            nol = "0"
            kd = (tg + nol + no)
            ElseIf (no < 100) Then
            tg = Right(Format(Date, "MM/dd/yyyy"), 2) + Left(Format(Date, "MM/dd/yyyy"), 2) + Mid(Format(Date, "MM/dd/yyyy"), 4, 2)
            nol = ""
            kd = (tg + nol + no)
            End If
    
    End If
    End If
     
no_masuk = kd
rskode.Close
End Function

Function K_Pinjam()
Dim kd As String
Dim no As String
Dim nol As String
Dim tg As String

rskode.Open "select no_pinjam from t_trans" & _
        " order by [no_pinjam]", mydb, adOpenStatic
        
    If rskode.EOF Then
    tg = Right(Format(Date, "MM/dd/yyyy"), 2) + Left(Format(Date, "MM/dd/yyyy"), 2) + Mid(Format(Date, "MM/dd/yyyy"), 4, 2)
    kd = tg + "001"
    
    Else
    rskode.MoveLast
            
            If Left(rskode.Fields("no_pinjam"), 6) <> Right(Format(Date, "MM/dd/yyyy"), 2) + Left(Format(Date, "MM/dd/yyyy"), 2) + Mid(Format(Date, "MM/dd/yyyy"), 4, 2) Then
            tg = Right(Format(Date, "MM/dd/yyyy"), 2) + Left(Format(Date, "MM/dd/yyyy"), 2) + Mid(Format(Date, "MM/dd/yyyy"), 4, 2)
            kd = tg + "001"
            
            Else
            
            no = Right(rskode.Fields("no_pinjam"), 3) + 1
            If (no < 10) Then
            tg = Right(Format(Date, "MM/dd/yyyy"), 2) + Left(Format(Date, "MM/dd/yyyy"), 2) + Mid(Format(Date, "MM/dd/yyyy"), 4, 2)
            nol = "00"
            kd = (tg + nol + no)
            ElseIf (no < 100) Then
            tg = Right(Format(Date, "MM/dd/yyyy"), 2) + Left(Format(Date, "MM/dd/yyyy"), 2) + Mid(Format(Date, "MM/dd/yyyy"), 4, 2)
            nol = "0"
            kd = (tg + nol + no)
            ElseIf (no < 1000) Then
            tg = Right(Format(Date, "MM/dd/yyyy"), 2) + Left(Format(Date, "MM/dd/yyyy"), 2) + Mid(Format(Date, "MM/dd/yyyy"), 4, 2)
            nol = ""
            kd = (tg + nol + no)
            End If
    
    End If
    End If
     
no_pinjam = kd
rskode.Close
End Function

Laporan Buku
Dim rsb As Recordset
Dim sql As String

Private Sub Command1_Click()
If Option1.Value = True Then
    sql = "SELECT no_inventaris, T_buku.kode_buku, judul, nama_kategori, penerbit, pengarang" _
        & " FROM T_inventaris, T_buku, T_kategori" _
        & " WHERE T_buku.kode_kategori = T_kategori.kode_kategori" _
        & " AND T_inventaris.kode_buku = T_buku.kode_buku" _
        & " ORDER BY T_buku.kode_buku, no_inventaris"
    
    Set rsb = mydb.Execute(sql)
    If rsb.EOF Then
        MsgBox "DATA YANG DIMINTA KOSONG!", vbOKOnly, "INFO"
        Exit Sub
    End If
    
    data.Commands(4).CommandText = sql
    L_BukuSemua.Sections("Section4").Controls("label11").Caption = Format(Date, "dd/mm/yyyy")
    L_BukuSemua.Refresh
    data.rssemuabuku.Close
    L_BukuSemua.Show

ElseIf Option2.Value = True Then
    sql = "SELECT kode_buku, judul, nama_kategori, penerbit, pengarang" _
        & " FROM T_buku, T_kategori" _
        & " WHERE T_buku.kode_kategori = T_kategori.kode_kategori" _
        & " AND nama_kategori = '" & Combo1.Text & "'" _
        & " ORDER BY kode_buku"
    
    Set rsb = mydb.Execute(sql)
    If rsb.EOF Then
        MsgBox "DATA YANG DIMINTA KOSONG!", vbOKOnly, "INFO"
        Exit Sub
    End If
    
    data.Commands(4).CommandText = sql
    L_BukupKat.Sections("Section4").Controls("label11").Caption = Format(Date, "dd/mm/yyyy")
    L_BukupKat.Sections("Section4").Controls("label12").Caption = "LAPORAN DAFTAR BUKU, KATEGORI" + " '" + UCase(Combo1.Text) + "'"
    L_BukupKat.Refresh
    data.rssemuabuku.Close
    L_BukupKat.Show

ElseIf Option3.Value = True Then
    sql = "SELECT T_inventaris.no_inventaris, T_buku.kode_buku, judul, " _
        & " nama_kategori, penerbit, pengarang, T_anggota.no_anggota, " _
        & " nama, tgl_pinjam, tgl_pinjam+2 as tgl_kembali" _
        & " FROM T_buku, T_kategori, T_inventaris, T_anggota, T_trans, T_transpinjam" _
        & " Where T_buku.kode_kategori = T_kategori.kode_kategori " _
        & " AND T_inventaris.kode_buku = T_buku.kode_buku " _
        & " AND T_anggota.no_anggota = T_trans.no_anggota " _
        & " AND T_trans.no_pinjam = T_transpinjam.no_pinjam " _
        & " AND T_inventaris.no_inventaris = T_transpinjam.no_inventaris" _
        & " AND T_transpinjam.status_buku=" & 0 & "" _
        & " ORDER BY T_transpinjam.no_inventaris"
    
    Set rsb = mydb.Execute(sql)
    If rsb.EOF Then
        MsgBox "DATA YANG DIMINTA KOSONG!", vbOKOnly, "INFO"
        Exit Sub
    End If
    
    data.Commands(5).CommandText = sql
    L_BukuTerpinjam.Sections("Section4").Controls("label11").Caption = Format(Date, "dd/mm/yyyy")
    L_BukuTerpinjam.Refresh
    L_BukuTerpinjam.Show
    
ElseIf Option4.Value = True Then
    sql = "SELECT T_inventaris.no_inventaris, judul, status,nama_kategori" _
        & " From T_buku, T_inventaris, T_inventaris_dt, T_kategori" _
        & " Where T_buku.kode_buku = T_inventaris.kode_buku" _
        & " AND T_inventaris.status_buku = T_inventaris_dt.status_buku" _
        & " AND T_kategori.kode_kategori = T_buku.kode_kategori" _
        & " AND T_inventaris.status_buku >= " & 3 & "" _
        & " AND T_inventaris.status_buku <= " & 4 & "" _
        & " ORDER BY no_inventaris"
    
    Set rsb = mydb.Execute(sql)
    If rsb.EOF Then
        MsgBox "DATA YANG DIMINTA KOSONG!", vbOKOnly, "INFO"
        Exit Sub
    End If
    
    data.Commands(6).CommandText = sql
    L_BukuError.Sections("Section4").Controls("label11").Caption = Format(Date, "dd/mm/yyyy")
    L_BukuError.Refresh
    L_BukuError.Show
    
End If
End Sub

Private Sub Command2_Click()
Option1.Value = True

End Sub

Private Sub Command3_Click()
Call Buka(True)
Unload Me
End Sub

Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
BukaDB

rs.Open "SELECT nama_kategori FROM T_kategori" & _
        " ORDER BY nama_kategori", mydb, adOpenStatic
While Not rs.EOF
    Combo1.AddItem (rs.Fields("nama_kategori"))
    rs.MoveNext
Wend
rs.Close
End Sub

Private Sub Option1_Click()
If Option1.Value = True Then
Combo1.Enabled = False
End If
End Sub

Private Sub Option2_Click()
If Option2.Value = True Then
Combo1.Enabled = True
End If
End Sub

Private Sub Option3_Click()
If Option3.Value = True Then
Combo1.Enabled = False
End If
End Sub

Private Sub Option4_Click()
If Option4.Value = True Then
Combo1.Enabled = False
End If
End Sub

Laporan Peminjaman
Private Sub Command1_Click()
If Option1.Value = True Then
    sql = "SELECT T_inventaris.no_inventaris, T_buku.kode_buku, judul, " _
        & " nama_kategori, penerbit, pengarang, T_anggota.no_anggota, " _
        & " nama, tgl_pinjam, tgl_pinjam + perpanjang + 7 as tgl_kembali" _
        & " FROM T_buku, T_kategori, T_inventaris, T_anggota, T_trans, T_transpinjam" _
        & " Where T_buku.kode_kategori = T_kategori.kode_kategori " _
        & " AND T_inventaris.kode_buku = T_buku.kode_buku " _
        & " AND T_anggota.no_anggota = T_trans.no_anggota " _
        & " AND T_trans.no_pinjam = T_transpinjam.no_pinjam " _
        & " AND T_inventaris.no_inventaris = T_transpinjam.no_inventaris" _
        & " AND tgl_pinjam='" & Format(date1.Value, "MM/dd/yyyy") & "' " _
        & " ORDER BY T_transpinjam.no_inventaris"
    
    Set rsb = mydb.Execute(sql)
    If rsb.EOF Then
        MsgBox "DATA YANG DIMINTA KOSONG!", vbOKOnly, "INFO"
        Exit Sub
    End If
    
    data.Commands(9).CommandText = sql
    L_pinjamhari.Sections("Section4").Controls("label11").Caption = Format(Date, "dd/mm/yyyy")
    L_pinjamhari.Refresh
    L_pinjamhari.Show
    
ElseIf Option2.Value = True Then
    sql = "SELECT T_inventaris.no_inventaris, T_buku.kode_buku, judul, " _
        & " nama_kategori, penerbit, pengarang, T_anggota.no_anggota, " _
        & " nama, tgl_pinjam, tgl_pinjam + perpanjang + 7 as tgl_kembali" _
        & " FROM T_buku, T_kategori, T_inventaris, T_anggota, T_trans, T_transpinjam" _
        & " Where T_buku.kode_kategori = T_kategori.kode_kategori " _
        & " AND T_inventaris.kode_buku = T_buku.kode_buku " _
        & " AND T_anggota.no_anggota = T_trans.no_anggota " _
        & " AND T_trans.no_pinjam = T_transpinjam.no_pinjam " _
        & " AND T_inventaris.no_inventaris = T_transpinjam.no_inventaris" _
        & " AND tgl_pinjam >='" & Format(date1.Value, "MM/dd/yyyy") & "' " _
        & " AND tgl_pinjam <='" & Format(date2.Value, "MM/dd/yyyy") & "' " _
        & " ORDER BY tgl_pinjam"
    
    Set rsb = mydb.Execute(sql)
    If rsb.EOF Then
        MsgBox "DATA YANG DIMINTA KOSONG!", vbOKOnly, "INFO"
        Exit Sub
    End If
    
    data.Commands(9).CommandText = sql
    L_PinjamPeriode.Sections("Section4").Controls("label11").Caption = Format(Date, "dd/mm/yyyy")
    L_PinjamPeriode.Refresh
    L_PinjamPeriode.Show
    
End If
End Sub

Private Sub Command2_Click()
date1.Value = (Date)
date2.Value = (Date)
date2.Enabled = False
date1.Enabled = True
Option1.Value = True
End Sub

Private Sub Command3_Click()
Call Buka(True)
Unload Me
End Sub

Private Sub date1_Change()
If Option2.Value = True Then
    If date2.Value < date1.Value Then
    MsgBox "Tanggal Pertama Harus lebih Besar atau Sama dengan Tanggal Terakhir", vbCritical
    date1.Value = date2.Value
End If
End If
End Sub

Private Sub date2_Change()
If date2.Value < date1.Value Then
MsgBox "Tanggal Terakhir Harus Lebih besar / Sama Dengan Tanggal Pertama", vbCritical
date2.Value = date1.Value
End If
End Sub

Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
BukaDB

End Sub

Private Sub Option1_Click()
date2.Enabled = False
End Sub

Private Sub Option2_Click()
date2.Enabled = True
End Sub