LAMPIRAN
Form menu login
Private Sub cmdcancel_Click() LoginSucceeded = False Shape1.Visible = False lblusername.Visible = False lblpassword.Visible = False txtusername.Visible = False txtpassword.Visible = False cmdok.Visible = False cmdcancel.Visible = False lblexit.Visible = True
lbllogin.Visible = True txtusername = "" txtpassword = "" End Sub
Private Sub cmdok_Click() If txtusername.Text = "" Then
MsgBox "Masukkan username Anda", vbInformation, "Confirmation" txtusername.SetFocus
Exit Sub End If
If txtpassword.Text = "" Then
MsgBox "Masukkan Password Anda", vbCritical, "Confirmation" txtusername.SetFocus
End If
MsgBox "Login Anda Sukses", vbInformation, "Pesan" Me.Hide
mnutama.Show vbModal
MsgBox "AKSES DI TOLAK", vbCritical + vbOKOnly, "Pesan" txtusername = ""
txtpassword = "" End Sub
Private Sub Form_Activate() Me.Caption = "..::LOGIN::.." lbllogin.Visible = True lblexit.Visible = True Shape1.Visible = False lblusername.Visible = False lblpassword.Visible = False txtpassword.Visible = False txtusername.Visible = False cmdok.Visible = False cmdcancel.Visible = False
txtusername.Text = "" txtpassword.Text = "" End Sub
Private Sub lblexit_Click() Unload Me
End Sub
lbllogin.Visible = False txtusername.SetFocus End Sub
Private Sub Form_Load() i = 0
Timer2.Interval = 500
Label2.Caption = "SMP SWASTA ISLAM AFIFIYAH JLN.PURI NO 154 MEDAN"
End Sub
Private Sub Timer1_Timer() Label1.Left = Label1.Left - 20 If Label1.Left <= -3015 Then Label1.Left = Me.Width End If
End Sub
Private Sub Timer2_Timer() Dim i As Long
Dim merah As Integer, hijau As Integer, biru As Integer i = i + 1
If i = 1000000 Then i = 0 merah = Int(255 * Rnd) hijau = Int(255 * Rnd) biru = Int(255 * Rnd)
Label1.ForeColor = RGB(merah, putih, biru) Label2.ForeColor = RGB(biru, putih, merah) If i Mod 2 = 0 Then
Label2.Visible = True Else
Label2.Visible = True End If
End Sub
Private Sub txtpassword_KeyUp(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then
cmdok_Click End If
Private Sub txtusername_KeyUp(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then
txtpassword.SetFocus End If
End Sub
Form menu utama
Private Sub Timer2_Timer() Dim i As Long
Dim merah As Integer, hijau As Integer, biru As Integer i = i + 1
If i = 1000000 Then i = 0 merah = Int(255 * Rnd) hijau = Int(255 * Rnd) biru = Int(255 * Rnd)
Label1.ForeColor = RGB(hijau, putih, biru) Label1.ForeColor = RGB(biru, putih, hijau) If i Mod 2 = 0 Then
Label2.Visible = True Else
Label2.Visible = True End If
End Sub
Private Sub Form_Load() i = 0
Timer2.Interval = 500 Timer2.Interval = 500
Label1.Caption = "Perpustakaaan Sekolah SMP Swasta Islam Afifiyah " End Sub
Private Sub Timer3_Timer() Label1.Left = Label1.Left - 20 If Label1.Left <= -3015 Then Label1.Left = Me.Width End If
End Sub
If KeyAscii = 27 Then End End Sub
Private Sub MNDATASISWA_Click() datasiswa.Show vbModal
End Sub
Private Sub MNDATABUKU_Click() databuku.Show vbModal
End Sub
Private Sub MNPEMINJAMANBUKU_Click() transaksipeminjamanbuku.Show vbModal End Sub
Private Sub MNDATA_PEMINJAMANBUKU_Click() PEMINJAMANBUKU.Show vbModal
End Sub
Private Sub MNPENGEMBALIANBUKU_Click() transaksipengembalianbuku.Show vbModal
End Sub
Private Sub MNKARTUSISWA_Click() Kartusiswa.Show vbModal
End Sub
Private Sub mndaftarbuku_Click() Daftarbuku.Show vbModal
End Sub
Private Sub mnsiswa_Click() lapdatasiswa.Show vbModal End Sub
Private Sub mnpeminjaman_Click() lappeminjamanbuku.Show vbModal End Sub
Private Sub mnpengembalian_Click() lappengembalianbuku.Show vbModal End Sub
Private Sub mnkartu_Click() CetakKrtu.Show vbModal End Sub
Private Sub mnprofilsekolah_Click() Profilsekolah.Show vbModal
End Sub
Private Sub mnprogrammer_Click() Info.Show vbModal
End Sub
Private Sub mnexit_Click() Dim MB As Byte
MB = MsgBox("Anda Yakin Keluar...?", vbYesNo + vbInformation, "Pesan") If MB = vbYes Then
End End If End Sub
Form data siswa
Private Sub Form_Activate() Call BukaDB
Adodc1.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database.mdb"
Adodc1.ConnectionString = Conn.ConnectionString
Adodc1.RecordSource = "SELECT * FROM datasiswa ORDER BY Nomorinduk" Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1 DataGrid1.Refresh
Sub Form_Load() Text1.MaxLength = 20 Text2.MaxLength = 30
Call BukaDB
Combo1.AddItem "Laki-Laki" Combo1.AddItem "Perempuan" Combo3.AddItem i
DTPicker1 = Date KondisiAwal End Sub
Function CariData() Call BukaDB
RSdatasiswa.Open "Select * from datasiswa where Nama='" & Text2 & "'", Conn End Function
Private Sub KosongkanText() Text1 = ""
Text2 = "" Text3 = "" Combo1 = "" Combo2 = "" Combo3 = "" End Sub
Private Sub SiapIsi() Text1.Enabled = True Text2.Enabled = True Text3.Enabled = True Combo1.Enabled = True Combo2.Enabled = True Combo3.Enabled = True End Sub
Text3.Enabled = False Combo1.Enabled = False Combo2.Enabled = False Combo3.Enabled = False End Sub
Private Sub KondisiAwal() KosongkanText
TidakSiapIsi
CmdInput.Caption = "&Input" CmdEdit.Caption = "&Edit" CmdHapus.Caption = "&Hapus" CmdTutup.Caption = "&Tutup" CmdInput.Enabled = True CmdEdit.Enabled = True CmdHapus.Enabled = True End Sub
Private Sub TampilkanData() With RSdatasiswa
If Not RSdatasiswa.EOF Then Text2 = RSdatasiswa!Nama
DTPicker1 = RSdatasiswa!TglLahir Combo1 = RSdatasiswa!JenisKelamin Text3 = RSdatasiswa!Alamat
Combo2 = RSdatasiswa!Agama Combo3 = RSdatasiswa!Kelas End If
End With End Sub
Private Sub CmdInput_Click()
If CmdInput.Caption = "&Input" Then CmdInput.Caption = "&Simpan" CmdEdit.Enabled = False
CmdHapus.Enabled = False CmdTutup.Caption = "&Batal" SiapIsi
Else
If Text1 = "" Or Text2 = "" Or DTPicker1 = "" Or Combo1 = "" Or Text3 = "" Or Combo2 = "" Or Combo3 = "" Then
MsgBox "Data Belum Lengkap...!" Else
Dim SQLTambah As String
SQLTambah = "Insert Into datasiswa
(Nomorinduk,Nama,TglLahir,Jeniskelamin,Alamat,Agama,Kelas) values ('" & Text1 & "','" & Text2 & "','" & DTPicker1 & "','" & Combo1 & "','" & Text3 & "','" & Combo2 & "','" & Combo3 & "')"
Conn.Execute SQLTambah Call KondisiAwal
Form_Activate End If
End If End Sub
Private Sub CmdEdit_Click()
If CmdEdit.Caption = "&Edit" Then CmdInput.Enabled = False
CmdEdit.Caption = "&Simpan" CmdHapus.Enabled = False CmdTutup.Caption = "&Batal" SiapIsi
Text1.SetFocus Else
If Text2 = "" Or DTPicker1 = "" Or Combo1 = "" Or Text3 = "" Or Combo2 = "" Or Combo3 = "" Then
MsgBox "Masih Ada Data Yang Kosong" Else
Dim SQLEdit As String
SQLEdit = "Update datasiswa Set Nama= '" & Text2 & "', TglLahir='" & DTPicker1 & "', Jeniskelamin = '" & Combo1 & "',Alamat='" & Text3 & "', Agama='" & Combo2 & "', Kelas='" & Combo3 & "' where Nomorinduk='" & Text1 & "'" Conn.Execute SQLEdit
Call KondisiAwal Form_Activate End If
End Sub
Private Sub Cmdsearch_Click() CmdSearch.Visible = Enabled
Dim i As String
Dim RS As New ADODB.Recordset
i = InputBox("Silahkan masukkan Nama yang ingin anda cari!", "Search") If i = "" Then
CmdSearch.Visible = True Exit Sub
Else Text1 = i
Set RS = New ADODB.Recordset
RS.Open " select* from datasiswa where Nama = '" & Text1 & "'", Conn If Not RS.EOF Then
Text1 = RS.Fields(0) Text2 = RS.Fields(1) DTPicker1 = RS.Fields(2) Combo1 = RS.Fields(3) Text3 = RS.Fields(4) Combo2 = RS.Fields(5) Combo3 = RS.Fields(6) Exit Sub
CmdEdit_Click Else
MsgBox "Data yang anda cari tidak ditemukan....!", vbOKOnly + vbInformation, "Search"
Text1.Text = ""
CmdSearch.Visible = True Exit Sub
End If End If End Sub
Private Sub CmdHapus_Click()
CmdInput.Enabled = False CmdEdit.Enabled = False CmdTutup.Caption = "&Batal" DataGrid1.Refresh
Adodc1.Refresh KosongkanText SiapIsi
Text1.SetFocus End If
End Sub
Private Sub CmdTutup_Click() Select Case CmdTutup.Caption Case "&Tutup"
Unload Me Case "&Batal" TidakSiapIsi KondisiAwal End Select
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then If Len(Text1) < 4 Then
MsgBox "Kode Harus 4 Digit" Text1.SetFocus
Else
Text2.SetFocus End If
If CmdInput.Caption = "SIMPAN" Then Call CariData
If Not RSdatasiswa.EOF Then TampilkanData
MsgBox "Kode datasiswa Sudah Ada" KosongkanText
Text1.SetFocus Else
End If
If CmdEdit.Caption = "SIMPAN" Then Call CariData
If Not RSdatasiswa.EOF Then TampilkanData
Text1.Enabled = False Text2.SetFocus Else
MsgBox "Kode datasiswa Tidak Ada" Text1 = ""
Text1.SetFocus End If
End If
If CmdHapus.Enabled = True Then Call CariData
If Not RSdatasiswa.EOF Then TampilkanData
pesan = MsgBox("Yakin akan dihapus", vbYesNo) If pesan = vbYes Then
Dim SQLHapus As String
SQLHapus = "Delete From datasiswa where Nama= '" & Text2 & "'" Conn.Execute SQLHapus
Call KondisiAwal DataGrid1.Refresh Adodc1.Refresh Form_Activate DataGrid1.Refresh Adodc1.Refresh CmdHapus.SetFocus Else
Call KondisiAwal Form_Activate CmdHapus.SetFocus End If
Else
End If End If End If End Sub
Private Sub TEXT2_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then DTPicker1.SetFocus End Sub
Private Sub DTPicker1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Combo2.SetFocus
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then KeyAscii = 0
End Sub
Private Sub Combo2_Keypress(KeyAscii As Integer) If KeyAscii = 13 Then Text3.SetFocus
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then KeyAscii = 0
End Sub
Private Sub Text3_(KeyAscii As Integer) If KeyAscii = 13 Then Combo3.SetFocus
End Sub
Private Sub Combo3_Keypress(KeyAscii As Integer) If KeyAscii = 13 Then
If CmdInput.Enabled = True Then CmdInput.SetFocus
ElseIf CmdEdit.Enabled = True Then CmdEdit.SetFocus
End If End If
End Sub
Function CariGrid() Call BukaDB
'mencari kode datasiswa yang ada dalam grid di kolom 0
RSdatasiswa.Open "Select * From datasiswa where Nomorinduk='" & DataGrid1.Columns(0) & "'", Conn
End Function
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode
'jika menekan enter setelah memilih data Case vbKeyReturn
'jika cmdedit caption-nya simpan maka If CmdEdit.Caption = "&Simpan" Then 'panggil prosedur SelectAllVisible1 Call SelectAllVisible1
Text2.SetFocus
'jika cmdhapus caption-nya hapus maka ElseIf CmdHapus.Caption = "&Hapus" Then 'panggil prosedur SelectAllVisible2 Call SelectAllVisible2
End If
Case vbKeyEscape KondisiAwal
CmdHapus.SetFocus End Select
End Sub
Sub SelectAllVisible1()
'jika text1 tidak sama dengan isi grid kolom 0 maka If Text1 <> DataGrid1.Columns(0) Then
'ubah text1 menjadi isi grid kolom 0 (Nomorinduk) Text1 = DataGrid1.Columns(0)
'panggil prosedur caridata Call CariData
'text1 (Nomorinduk) dinonaktifkan Text1.Enabled = False
Text1 = DataGrid1.Columns(0) Text2 = DataGrid1.Columns(1) DTPicker1 = DataGrid1.Columns(2) Combo1 = DataGrid1.Columns(3) Text3 = DataGrid1.Columns(4) Combo2 = DataGrid1.Columns(5) Combo3 = DataGrid1.Columns(6)
Text1.SetFocus End If
End Sub
Sub SelectAllVisible2()
If Text1 <> DataGrid1.Columns(0) Then Text1 = DataGrid1.Columns(0) Call CariData
Text1.Enabled = False
Text1 = DataGrid1.Columns(0) Text2 = DataGrid1.Columns(1)
'jika semua textbox telah terisi dan kode datasiswa ditemukan 'munculkan pesan penghapusan
pesan = MsgBox("Yakin akan dihapus..?", vbYesNo, "Konfirmasi") 'jika dijawab YES
If pesan = vbYes Then 'hapus data
Dim SQLHapus As String
SQLHapus = "Delete From datasiswa where Nama= '" & Text2 & "'" Conn.Execute SQLHapus
DataGrid1.Refresh Adodc1.Refresh KondisiAwal
CmdHapus.SetFocus Else
'jika dijawab NO kembali ke kondisi awal KondisiAwal
CmdHapus.SetFocus End If
Private Sub Text2_Change()
Adodc1.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database.mdb"
Adodc1.ConnectionString = Conn.ConnectionString
Adodc1.RecordSource = "select * from datasiswa where Nama like '%" & Text2 & "%'"
Adodc1.Refresh DataGrid1.Refresh
Set DataGrid1.DataSource = Adodc1 DataGrid1.Refresh
End Sub
Form data buku
Private Sub Form_Activate() Call BukaDB
Adodc1.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database.mdb"
Adodc1.ConnectionString = Conn.ConnectionString
Adodc1.RecordSource = "SELECT * FROM databuku ORDER BY Kodebuku" Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1 DataGrid1.Refresh
End Sub
Function CariData() Call BukaDB
RSdatabuku.Open "Select * From databuku where Kodebuku='" & Text1 & "'", Conn
End Function
Private Sub KosongkanText() Text1 = ""
End Sub
Private Sub SiapIsi() Text1.Enabled = True Text2.Enabled = True Text3.Enabled = True Text4.Enabled = True End Sub
Private Sub TidakSiapIsi() Text1.Enabled = False Text2.Enabled = False Text3.Enabled = False Text4.Enabled = False End Sub
Private Sub KondisiAwal() KosongkanText
TidakSiapIsi
CmdInput.Caption = "&Input" CmdEdit.Caption = "&Edit" CmdHapus.Caption = "&Hapus" CmdTutup.Caption = "&Tutup" CmdInput.Enabled = True CmdEdit.Enabled = True CmdHapus.Enabled = True End Sub
Private Sub TampilkanData() With RSdatabuku
If Not RSdatabuku.EOF Then Text2 = RSdatabuku!Judul Text3 = RSdatabuku!Penerbit Text4 = RSdatabuku!Pengarang
End If End With End Sub
If CmdInput.Caption = "&Input" Then CmdInput.Caption = "&Simpan" CmdEdit.Enabled = False
CmdHapus.Enabled = False CmdTutup.Caption = "&Batal" SiapIsi
KosongkanText Text1.SetFocus Else
If Text1 = "" Or Text2 = "" Or Text3 = "" Or Text4 = "" Then MsgBox "Data Belum Lengkap...!"
Else
Dim SQLTambah As String
SQLTambah = "Insert Into databuku (Kodebuku,Judul,Penerbit,Pengarang) values ('" & Text1 & "','" & Text2 & "','" & Text3 & "','" & Text4 & "')"
Conn.Execute SQLTambah Call KondisiAwal
Form_Activate End If
End If End Sub
Private Sub CmdEdit_Click()
If CmdEdit.Caption = "&Edit" Then CmdInput.Enabled = False
CmdEdit.Caption = "&Simpan" CmdHapus.Enabled = False CmdTutup.Caption = "&Batal" SiapIsi
Text1.SetFocus Else
If Text2 = "" Or Text3 = "" Or Text4 = "" Then MsgBox "Masih Ada Data Yang Kosong" Else
Dim SQLEdit As String
SQLEdit = "Update databuku Set Judul= '" & Text2 & "', Penerbit='" & Text3 & "', Pengarang='" & Text4 & "' where Kodebuku='" & Text1 & "'"
Form_Activate End If
End If End Sub
Private Sub Cmdsearch_Click() CmdSearch.Visible = Enabled
Dim i As String
Dim RS As New ADODB.Recordset
i = InputBox("Silahkan masukkan Kode Buku yang ingin anda cari!", "Search") If i = "" Then
CmdSearch.Visible = True Exit Sub
Else Text1 = i
Set RS = New ADODB.Recordset
RS.Open " select*from databuku where Kodebuku = '" & Text1 & "'", Conn If Not RS.EOF Then
Text1 = RS.Fields(0) Text2 = RS.Fields(1) Text3 = RS.Fields(2) Text4 = RS.Fields(3) Exit Sub
CmdEdit_Click Else
MsgBox "Data yang anda cari tidak ditemukan....!", vbOKOnly + vbInformation, "Search"
Text1.Text = ""
CmdSearch.Visible = True Exit Sub
End If End If End Sub
Private Sub CmdHapus_Click()
If CmdHapus.Caption = "&Hapus" Then CmdInput.Enabled = False
CmdTutup.Caption = "&Batal" KosongkanText
SiapIsi
Text1.SetFocus End If
End Sub
Private Sub CmdTutup_Click() Select Case CmdTutup.Caption Case "&Tutup"
Unload Me Case "&Batal" TidakSiapIsi KondisiAwal End Select
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then If Len(Text1) < 4 Then
MsgBox "Kode Harus 4 Digit" Text1.SetFocus
Else
Text2.SetFocus End If
If CmdInput.Caption = "SIMPAN" Then Call CariData
If Not RSdatabuku.EOF Then TampilkanData
MsgBox "Kode databuku Sudah Ada" KosongkanText
Text1.SetFocus Else
Text2.SetFocus End If
End If
Call CariData
If Not RSdatabuku.EOF Then TampilkanData
Text1.Enabled = False Text2.SetFocus Else
MsgBox "Kode databuku Tidak Ada" Text1 = ""
Text1.SetFocus End If
End If
If CmdHapus.Enabled = True Then Call CariData
If Not RSdatabuku.EOF Then TampilkanData
pesan = MsgBox("Yakin akan dihapus", vbYesNo) If pesan = vbYes Then
Dim SQLHapus As String
SQLHapus = "Delete From databuku where Kodebuku= '" & Text1 & "'" Conn.Execute SQLHapus
Call KondisiAwal Form_Activate CmdHapus.SetFocus Else
Call KondisiAwal Form_Activate CmdHapus.SetFocus End If
Else
MsgBox "Data Tidak ditemukan" Text1.SetFocus
End If End If End If End Sub
Private Sub TEXT2_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
Private Sub Text3_Keypress(KeyAscii As Integer) If KeyAscii = 13 Then Text4.SetFocus
End Sub
Private Sub TEXT4_Keypress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
Function CariGrid() Call BukaDB
'mencari kode databuku yang ada dalam grid di kolom 0
RSdatabuku.Open "Select * From databuku where Kodebuku='" & DataGrid1.Columns(0) & "'", Conn
End Function
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode
'jika menekan enter setelah memilih data Case vbKeyReturn
'jika cmdedit caption-nya simpan maka If CmdEdit.Caption = "&Simpan" Then 'panggil prosedur SelectAllVisible1 Call SelectAllVisible1
Text2.SetFocus
'jika cmdhapus caption-nya hapus maka ElseIf CmdHapus.Caption = "&Hapus" Then 'panggil prosedur SelectAllVisible2 Call SelectAllVisible2
End If
Case vbKeyEscape KondisiAwal
CmdHapus.SetFocus End Select
Sub SelectAllVisible1()
'jika text1 tidak sama dengan isi grid kolom 0 maka If Text1 <> DataGrid1.Columns(0) Then
'ubah text1 menjadi isi grid kolom 0 (Kodebuku) Text1 = DataGrid1.Columns(0)
'panggil prosedur caridata Call CariData
'text1 (Kodebuku) dinonaktifkan Text1.Enabled = False
'pindahkan isi grid kolom 0 ke text1 dan seterusnya Text1 = DataGrid1.Columns(0)
Text2 = DataGrid1.Columns(1) Text3 = DataGrid1.Columns(2) Text4 = DataGrid1.Columns(3) Text1.SetFocus
End If End Sub
Sub SelectAllVisible2()
If Text1 <> DataGrid1.Columns(0) Then Text1 = DataGrid1.Columns(0) Call CariData
Text1.Enabled = False
'jika semua textbox telah terisi dan kode databuku ditemukan 'munculkan pesan penghapusan
pesan = MsgBox("Yakin akan dihapus..?", vbYesNo, "Konfirmasi") 'jika dijawab YES
If pesan = vbYes Then 'hapus data
Dim SQLHapus As String
SQLHapus = "Delete From databuku where Kodebuku= '" & Text1 & "'" Conn.Execute SQLHapus
DataGrid1.Refresh KondisiAwal
CmdHapus.SetFocus Else
CmdHapus.SetFocus End If
End If End Sub
Private Sub Text1_Change()
Adodc1.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database.mdb"
Adodc1.ConnectionString = Conn.ConnectionString
Adodc1.RecordSource = "select * from databuku where Kodebuku like '%" & Text1 & "%'"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1 DataGrid1.Refresh
End Sub
Form Transaksi peminjaman buku
Private Sub Form_Activate() Call BukaDB
Adodc1.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database.mdb"
Adodc1.ConnectionString = Conn.ConnectionString
Adodc1.RecordSource = "SELECT * FROM transaksipeminjaman ORDER BY KodeBuku"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1 DataGrid1.Refresh
End Sub
Function CariData() Call BukaDB
RStransaksipengembalian.Open "Select * From transaksipengembalian where Nama='" & Text2 & "'", Conn
End Function
Private Sub KosongkanText() Text1 = ""
Text4 = "" Text5 = "" Text6 = "" End Sub
Private Sub SiapIsi() Text1.Enabled = True Text2.Enabled = True Text3.Enabled = True Text4.Enabled = True Text5.Enabled = True Text6.Enabled = True End Sub
Private Sub TidakSiapIsi() Text1.Enabled = False Text2.Enabled = False Text3.Enabled = False Text4.Enabled = False Text5.Enabled = False Text6.Enabled = False End Sub
Private Sub KondisiAwal() KosongkanText
TidakSiapIsi
CmdInput.Caption = "&Input" CmdEdit.Caption = "&Edit" CmdHapus.Caption = "&Hapus" CmdTutup.Caption = "&Tutup" CmdInput.Enabled = True CmdEdit.Enabled = True CmdHapus.Enabled = True End Sub
Private Sub TampilkanData() With RStransaksipeminjaman
Text4 = RStransaksipeminjaman!JudulBuku Text5 = RStransaksipeminjaman!Penerbit Text6 = RStransaksipeminjaman!Pengarang
DTPicker1 = RStransaksipeminjaman!TanggalPinjam DTPicker2 = RStransaksipeminjaman!TanggalKembali End If
End With End Sub
Private Sub CmdInput_Click()
If CmdInput.Caption = "&Input" Then CmdInput.Caption = "&Simpan" CmdEdit.Enabled = False
CmdHapus.Enabled = False CmdTutup.Caption = "&Batal" SiapIsi
KosongkanText Text1.SetFocus Else
If Text1 = "" Or Text2 = "" Or Text3 = "" Or Text4 = "" Or Text5 = "" Or Text6 = "" Or DTPicker1 = "" Or DTPicker2 = "" Then
MsgBox "Data Belum Lengkap...!" Else
Dim SQLTambah As String
SQLTambah = "Insert Into transaksipeminjaman
(Nomorinduk,Nama,KodeBuku,Judul,Penerbit,Pengarang,Tanggalpinjam,Tanggalkem bali) values ('" & Text1 & "','" & Text2 & "','" & Text3 & "','" & Text4 & "','" & Text5 & "','" & Text6 & "', '" & DTPicker1 & "','" & DTPicker2 & "')"
Conn.Execute SQLTambah Call KondisiAwal
Form_Activate End If
End If End Sub
Private Sub CmdEdit_Click()
If CmdEdit.Caption = "&Edit" Then CmdInput.Enabled = False
CmdHapus.Enabled = False CmdTutup.Caption = "&Batal" SiapIsi
Text1.SetFocus Else
If Text1 = "" Or Text2 = "" Or Text3 = "" Or Text4 = "" Or Text5 = "" Or Text6 = "" Or DTPicker1 = "" Or DTPicker2 = "" Then
MsgBox "Masih Ada Data Yang Kosong" Else
Dim SQLEdit As String
SQLEdit = "Update transaksipeminjaman Set Nama= '" & Text2 & "', KodeBuku='" & Text3 & "', JudulBuku='" & Text4 & "',Penerbit='" & Text5 & "',Pengarang='" & Text5 & "',TanggalPinjam='" & DTPicker1 &
"',TanggalKembali='" & DTPicker2 & "' where Nomorinduk='" & Text1 & "'" Conn.Execute SQLEdit
Call KondisiAwal Form_Activate End If
End If End Sub
Private Sub Cmdsearch_Click() Dim i As String
Dim RS As New ADODB.Recordset
i = InputBox("Silahkan masukkan Nama yang ingin anda cari!", "Search") If i = "" Then
Cmdsearch.Visible = True Exit Sub
Else Text1 = i
Set RS = New ADODB.Recordset
RS.Open " select* from transaksipeminjaman where Nama = '" & Text1 & "'", Conn If Not RS.EOF Then
Text5 = RS.Fields(4) Text6 = RS.Fields(5) DTPicker1 = RS.Fields(6) DTPicker2 = RS.Fields(7)
Exit Sub
CmdEdit_Click Else
MsgBox "Data yang anda cari tidak ditemukan....!", vbOKOnly + vbInformation, "Search"
Text1.Text = ""
Cmdsearch.Visible = True Exit Sub
End If End If End Sub
Private Sub CmdHapus_Click()
If CmdHapus.Caption = "&Hapus" Then CmdInput.Enabled = False
CmdEdit.Enabled = False CmdTutup.Caption = "&Batal" KosongkanText
SiapIsi
Text1.SetFocus End If
End Sub
Private Sub CmdTutup_Click() Select Case CmdTutup.Caption Case "&Tutup"
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then If Len(Text1) < 4 Then
MsgBox "Kode Harus 4 Digit" Text1.SetFocus
Else
Text2.SetFocus End If
If CmdInput.Caption = "SIMPAN" Then Call CariData
If Not RStransaksipeminjaman.EOF Then TampilkanData
MsgBox "Kode transaksipeminjaman Sudah Ada" KosongkanText
Text1.SetFocus Else
Text2.SetFocus End If
End If
If CmdEdit.Caption = "SIMPAN" Then Call CariData
If Not RStransaksipeminjaman.EOF Then TampilkanData
Text1.Enabled = False Text2.SetFocus Else
MsgBox "Kode transaksipeminjaman Tidak Ada" Text1 = ""
Text1.SetFocus End If
End If
If CmdHapus.Enabled = True Then Call CariData
TampilkanData
pesan = MsgBox("Yakin akan dihapus", vbYesNo) If pesan = vbYes Then
Dim SQLHapus As String
SQLHapus = "Delete From transaksipeminjaman where Nomorinduk= '" & Text1 & "'"
Call KondisiAwal DataGrid1.Refresh Adodc1.Refresh Form_Activate CmdHapus.SetFocus Else
Call KondisiAwal Form_Activate CmdHapus.SetFocus End If
Else
MsgBox "Data Tidak ditemukan" Text1.SetFocus
End If End If End If End Sub
Private Sub TEXT2_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then Text3.SetFocus End Sub
Private Sub Text3_Keypress(KeyAscii As Integer) If KeyAscii = 13 Then Text4.SetFocus
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then KeyAscii = 0
End Sub
Private Sub TEXT4_Keypress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
Private Sub Text5_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then Text6.SetFocus End Sub
Private Sub Text6_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then DTPicker1.SetFocus End Sub
Private Sub DTPicker2_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
Function CariGrid() Call BukaDB
'mencari kode datasiswa yang ada dalam grid di kolom 0
RStransaksipeminjaman.Open "Select * From transaksipeminjaman where Nomorinduk='" & DataGrid1.Columns(0) & "'", Conn
End Function
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode
'jika menekan enter setelah memilih data Case vbKeyReturn
'jika cmdedit caption-nya simpan maka If CmdEdit.Caption = "&Simpan" Then 'panggil prosedur SelectAllVisible1 Call SelectAllVisible1
Text2.SetFocus
'jika cmdhapus caption-nya hapus maka ElseIf CmdHapus.Caption = "&Hapus" Then 'panggil prosedur SelectAllVisible2 Call SelectAllVisible2
End If
Case vbKeyEscape KondisiAwal
End Sub
Sub SelectAllVisible1()
'jika text1 tidak sama dengan isi grid kolom 0 maka If Text1 <> DataGrid1.Columns(0) Then
'ubah text1 menjadi isi grid kolom 0 (Nomorinduk) Text1 = DataGrid1.Columns(0)
'panggil prosedur caridata Call CariData
'text1 (Nomorinduk) dinonaktifkan Text1.Enabled = False
Text1 = DataGrid1.Columns(0) Text2 = DataGrid1.Columns(1) Text3 = DataGrid1.Columns(2) Text4 = DataGrid1.Columns(3) Text5 = DataGrid1.Columns(4) Text6 = DataGrid1.Columns(5) DTPicker1 = DataGrid1.Columns(6) DTPicker2 = DataGrid1.Columns(7)
'pindahkan isi grid kolom 0 ke text1 dan seterusnya
Text1.SetFocus End If
End Sub
Sub SelectAllVisible2()
If Text1 <> DataGrid1.Columns(0) Then Text1 = DataGrid1.Columns(0) Call CariData
Text1.Enabled = False
Text1 = DataGrid1.Columns(0) Text2 = DataGrid1.Columns(1)
'jika semua textbox telah terisi dan kode datasiswa ditemukan 'munculkan pesan penghapusan
pesan = MsgBox("Yakin akan dihapus..?", vbYesNo, "Konfirmasi") 'jika dijawab YES
If pesan = vbYes Then
'hapus data
Dim SQLHapus As String
SQLHapus = "Delete From transaksipeminjaman where Nama= '" & Text2 & "'"
Conn.Execute SQLHapus DataGrid1.Refresh Adodc1.Refresh KondisiAwal
CmdHapus.SetFocus Else
'jika dijawab NO kembali ke kondisi awal KondisiAwal
CmdHapus.SetFocus End If
End If End Sub
Private Sub Text2_Change()
Adodc1.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database.mdb"
Adodc1.ConnectionString = Conn.ConnectionString
Adodc1.RecordSource = "select * from transaksipeminjaman where Nama like '%" & Text2 & "%'"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1 DataGrid1.Refresh
End Sub
Form transaksi pengembalian buku
Private Sub Form_Activate() Call BukaDB
Adodc1.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database.mdb"
Adodc1.ConnectionString = Conn.ConnectionString
Adodc1.RecordSource = "SELECT * FROM transaksipengembalian ORDER BY KodeBuku"
Set DataGrid1.DataSource = Adodc1 DataGrid1.Refresh
End Sub
Function CariData() Call BukaDB
RStransaksipengembalian.Open "Select * From transaksipengembalian where Nama='" & Text2 & "'", Conn
End Function
Private Sub KosongkanText() Text1 = ""
Text2 = "" Text3 = "" Text4 = "" Text5 = "" Text6 = "" End Sub
Private Sub SiapIsi() Text1.Enabled = True Text2.Enabled = True Text3.Enabled = True Text4.Enabled = True Text5.Enabled = True Text6.Enabled = True End Sub
Private Sub TidakSiapIsi() Text1.Enabled = False Text2.Enabled = False Text3.Enabled = False Text4.Enabled = False Text5.Enabled = False Text6.Enabled = False End Sub
Private Sub KondisiAwal() KosongkanText
CmdInput.Caption = "&Input" CmdEdit.Caption = "&Edit" CmdHapus.Caption = "&Hapus" CmdTutup.Caption = "&Tutup" CmdInput.Enabled = True CmdEdit.Enabled = True CmdHapus.Enabled = True End Sub
Private Sub TampilkanData() With RStransaksipengembalian
If Not RStransaksipengembalian.EOF Then Text2 = RStransaksipengembalian!Nama Text3 = RStransaksipengembalian!KodeBuku Text4 = RStransaksipengembalian!JudulBuku Text5 = RStransaksipengembalian!Penerbit Text6 = RStransaksipengembalian!Pengarang
DTPicker1 = RStransaksipengembalian!TanggalPinjam DTPicker2 = RStransaksipengembalian!TanggalKembali DTPicker3 = RStransaksipengembalian!Tgldikembalikan Text7 = RStransaksipengembalian!Terlambat
Text8 = RStransaksipengembalian!Denda End If
End With End Sub
Private Sub CmdInput_Click()
If CmdInput.Caption = "&Input" Then CmdInput.Caption = "&Simpan" CmdEdit.Enabled = False
CmdHapus.Enabled = False CmdTutup.Caption = "&Batal" SiapIsi
KosongkanText Text1.SetFocus Else
If Text1 = "" Or Text2 = "" Or Text3 = "" Or Text4 = "" Or Text5 = "" Or Text6 = "" Or DTPicker1 = "" Or DTPicker2 = "" Or DTPicker3 = "" Or Text7 = "" Or Text8 = "" Then
Else
Dim SQLTambah As String
SQLTambah = "Insert Into transaksipengembalian
(Nomorinduk,Nama,KodeBuku,Judul,Penerbit,Pengarang,Tanggalpinjam,Tanggalkem bali,Tgldikembalikan,Terlambat,Denda) values ('" & Text1 & "','" & Text2 & "','" & Text3 & "','" & Text4 & "','" & Text5 & "','" & Text6 & "', '" & DTPicker1 & "','" & DTPicker2 & "','" & DTPicker3 & "','" & Text7 & "','" & Text8 & "')"
Conn.Execute SQLTambah Call KondisiAwal
Form_Activate End If
End If End Sub
Private Sub CmdEdit_Click()
If CmdEdit.Caption = "&Edit" Then CmdInput.Enabled = False
CmdEdit.Caption = "&Simpan" CmdHapus.Enabled = False CmdTutup.Caption = "&Batal" SiapIsi
Text1.SetFocus Else
If Text1 = "" Or Text2 = "" Or Text3 = "" Or Text4 = "" Or Text5 = "" Or Text6 = "" Or DTPicker1 = "" Or DTPicker2 = "" Or DTPicker3 = "" Or Text7 = "" Or Text8 = "" Then
MsgBox "Masih Ada Data Yang Kosong" Else
Dim SQLEdit As String
SQLEdit = "Update transaksipengembalian Set Nama= '" & Text2 & "', KodeBuku='" & Text3 & "', JudulBuku='" & Text4 & "',Penerbit='" & Text5 & "',Pengarang='" & Text5 & "',TanggalPinjam='" & DTPicker1 &
"',TanggalKembali='" & DTPicker2 & "'Tgldikembalikan='" & DTPicker3 &
"',Terlambat='" & Text7 & "',Denda='" & Text8 & "' where Nomorinduk='" & Text1 & "'"
End If End Sub
Private Sub Cmdsearch_Click() Dim i As String
Dim RS As New ADODB.Recordset
i = InputBox("Silahkan masukkan Nama yang ingin anda cari!", "Search") If i = "" Then
CmdSearch.Visible = True Exit Sub
Else Text1 = i
Set RS = New ADODB.Recordset
RS.Open " select* from transaksipengembalian where Nama = '" & Text1 & "'", Conn If Not RS.EOF Then
Text1 = RS.Fields(0) Text2 = RS.Fields(1) Text3 = RS.Fields(2) Text4 = RS.Fields(3) Text5 = RS.Fields(4) Text6 = RS.Fields(5) DTPicker1 = RS.Fields(6) DTPicker2 = RS.Fields(7) DTPicker3 = RS.Fields(8) Text7 = RS.Fields(9) Text6 = RS.Fields(10)
Exit Sub
CmdEdit_Click Else
MsgBox "Data yang anda cari tidak ditemukan....!", vbOKOnly + vbInformation, "Search"
Text1.Text = ""
End If End If End Sub
Private Sub CmdHapus_Click()
If CmdHapus.Caption = "&Hapus" Then CmdInput.Enabled = False
CmdEdit.Enabled = False CmdTutup.Caption = "&Batal" KosongkanText
SiapIsi
Text1.SetFocus End If
End Sub
Private Sub CmdTutup_Click() Select Case CmdTutup.Caption Case "&Tutup"
Unload Me Case "&Batal" TidakSiapIsi KondisiAwal End Select
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then If Len(Text1) < 4 Then
MsgBox "Kode Harus 4 Digit" Text1.SetFocus
Else
Text2.SetFocus End If
If CmdInput.Caption = "SIMPAN" Then Call CariData
MsgBox "Kode transaksipengembalian Sudah Ada" KosongkanText
Text1.SetFocus Else
Text2.SetFocus End If
End If
If CmdEdit.Caption = "SIMPAN" Then Call CariData
If Not RStransaksipengembalian.EOF Then TampilkanData
Text1.Enabled = False Text2.SetFocus Else
MsgBox "Kode transaksipengembalian Tidak Ada" Text1 = ""
Text1.SetFocus End If
End If
If CmdHapus.Enabled = True Then Call CariData
If Not RStransaksipengembalian.EOF Then TampilkanData
pesan = MsgBox("Yakin akan dihapus", vbYesNo) If pesan = vbYes Then
Dim SQLHapus As String
SQLHapus = "Delete From transaksipengembalian where Nomorinduk= '" & Text1 & "'"
Call KondisiAwal DataGrid1.Refresh Adodc1.Refresh Form_Activate CmdHapus.SetFocus Else
Else
MsgBox "Data Tidak ditemukan" Text1.SetFocus
End If End If End If End Sub
Private Sub TEXT2_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then Text3.SetFocus End Sub
Private Sub Text3_Keypress(KeyAscii As Integer) If KeyAscii = 13 Then Text4.SetFocus
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then KeyAscii = 0
End Sub
Private Sub TEXT4_Keypress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then Text5.SetFocus End Sub
Private Sub Text5_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then Text6.SetFocus End Sub
Private Sub Text6_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then DTPicker1.SetFocus End Sub
Private Sub DTPicker2_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
Call BukaDB
'mencari kode datasiswa yang ada dalam grid di kolom 0
RStransaksipengembalian.Open "Select * From transaksipengembalian where Nomorinduk='" & DataGrid1.Columns(0) & "'", Conn
End Function
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode
'jika menekan enter setelah memilih data Case vbKeyReturn
'jika cmdedit caption-nya simpan maka If CmdEdit.Caption = "&Simpan" Then 'panggil prosedur SelectAllVisible1 Call SelectAllVisible1
Text2.SetFocus
'jika cmdhapus caption-nya hapus maka ElseIf CmdHapus.Caption = "&Hapus" Then 'panggil prosedur SelectAllVisible2 Call SelectAllVisible2
End If
Case vbKeyEscape KondisiAwal
CmdHapus.SetFocus End Select
End Sub
Sub SelectAllVisible1()
'jika text1 tidak sama dengan isi grid kolom 0 maka If Text1 <> DataGrid1.Columns(0) Then
'ubah text1 menjadi isi grid kolom 0 (Nomorinduk) Text1 = DataGrid1.Columns(0)
'panggil prosedur caridata Call CariData
'text1 (Nomorinduk) dinonaktifkan Text1.Enabled = False
Text6 = DataGrid1.Columns(5) DTPicker1 = DataGrid1.Columns(6) DTPicker2 = DataGrid1.Columns(7) DTPicker3 = DataGrid1.Columns(8) Text7 = DataGrid1.Columns(9) Text8 = DataGrid1.Columns(10)
'pindahkan isi grid kolom 0 ke text1 dan seterusnya
Text1.SetFocus End If
End Sub
Sub SelectAllVisible2()
If Text1 <> DataGrid1.Columns(0) Then Text1 = DataGrid1.Columns(0) Call CariData
Text1.Enabled = False
Text1 = DataGrid1.Columns(0) Text2 = DataGrid1.Columns(1)
'jika semua textbox telah terisi dan kode datasiswa ditemukan 'munculkan pesan penghapusan
pesan = MsgBox("Yakin akan dihapus..?", vbYesNo, "Konfirmasi") 'jika dijawab YES
If pesan = vbYes Then 'hapus data
Dim SQLHapus As String
SQLHapus = "Delete From transaksipengembalian where Nama= '" & Text2 & "'"
Conn.Execute SQLHapus DataGrid1.Refresh Adodc1.Refresh KondisiAwal
CmdHapus.SetFocus Else
KondisiAwal
CmdHapus.SetFocus End If
End If End Sub
Private Sub Text2_Change()
Adodc1.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database.mdb"
Adodc1.ConnectionString = Conn.ConnectionString
Adodc1.RecordSource = "select * from transaksipengembalian where Nama like '%" & Text2 & "%'"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1 DataGrid1.Refresh
End Sub
Form menu kartu siswa
Private Sub CmdGo_Click() If Text1 = "" Then
Text1.SetFocus Exit Sub Else
Dim RS As New ADODB.Recordset Set RS = New ADODB.Recordset
RS.Open " select*from Kartusiswa where Nomorinduk = '" & Text1 & "'", Conn If Not RS.EOF Then
Text2 = RS.Fields(1) Combo1 = RS.Fields(2) Text3 = RS.Fields(3) Combo2 = RS.Fields(4) DTPicker1 = RS.Fields(5) Else
MsgBox "Data tidak ditemukan! Coba lagi ya!...", vbOKOnly + vbInformation, "Search"
Exit Sub
End Sub
Private Sub CmdPrint_Click() With CR6
.SelectionFormula = "{Kartusiswa.Nomorinduk}='" & Text1.Text & "'" .WindowMinButton = False
.WindowShowCancelBtn = True .WindowShowCloseBtn = True .WindowShowPrintBtn = True .WindowShowPrintSetupBtn = True .WindowState = crptMaximized
.WindowTitle = "LAPORAN KARTU ANGGOTA" .ReportFileName = App.Path & "\Kartu.rpt"
.Action = 1
.RetrieveDataFiles End With
End Sub
Private Sub Form_Activate() Call BukaDB
Adodc1.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database.mdb"
Adodc1.ConnectionString = Conn.ConnectionString
Adodc1.RecordSource = "SELECT * FROM Kartusiswa ORDER BY Nomorinduk" Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1 DataGrid1.Refresh
End Sub
Sub Form_Load() Text1.MaxLength = 20 Text2.MaxLength = 30
Call BukaDB
Combo1.AddItem "Laki-Laki" Combo1.AddItem "Perempuan" Combo2.AddItem i
KondisiAwal End Sub
Function CariData() Call BukaDB
RSkartusiswa.Open "Select * From kartusiswa where Nama='" & Text2 & "'", Conn
End Function
Private Sub KosongkanText() Text1 = ""
Text2 = "" Combo1 = "" Text3 = "" Combo2 = "" End Sub
Private Sub SiapIsi() Text1.Enabled = True Text2.Enabled = True Combo1.Enabled = True Text3.Enabled = True Combo2.Enabled = True End Sub
Private Sub TidakSiapIsi() Text1.Enabled = False Text2.Enabled = False Combo1.Enabled = False Text3.Enabled = False Combo2.Enabled = False End Sub
Private Sub KondisiAwal() KosongkanText
TidakSiapIsi
CmdTutup.Caption = "&Tutup" CmdInput.Enabled = True CmdEdit.Enabled = True CmdHapus.Enabled = True End Sub
Private Sub TampilkanData() With RSkartusiswa
If Not RSkartusiswa.EOF Then Text2 = RSkartusiswa!Nama
Combo1 = RSkartusiswa!JenisKelamin Text3 = RSkartusiswa!Alamat
Combo2 = RSkartusiswa!Kelas End If
End With End Sub
Private Sub CmdInput_Click()
If CmdInput.Caption = "&Input" Then CmdInput.Caption = "&Simpan" CmdEdit.Enabled = False
CmdHapus.Enabled = False CmdTutup.Caption = "&Batal" SiapIsi
KosongkanText Text1.SetFocus Else
If Text1 = "" Or Text2 = "" Or Combo1 = "" Or Text3 = "" Or Combo2 = "" Or DTPicker1 = "" Then
MsgBox "Data Belum Lengkap...!" Else
Dim SQLTambah As String
SQLTambah = "Insert Into kartusiswa
(Nomorinduk,Nama,JenisKelamin,Alamat,Kelas,Tanggalmasuk) values ('" & Text1 & "','" & Text2 & "','" & Combo1 & "','" & Text3 & "','" & Combo2 & "', '" &
DTPicker1 & "')"
Conn.Execute SQLTambah Call KondisiAwal
End If End Sub
Private Sub CmdEdit_Click()
If CmdEdit.Caption = "&Edit" Then CmdInput.Enabled = False
CmdEdit.Caption = "&Simpan" CmdHapus.Enabled = False CmdTutup.Caption = "&Batal" SiapIsi
Text1.SetFocus Else
If Text2 = "" Or Combo1 = "" Or Text3 = "" Or Combo2 = "" Or DTPicker1 = "" Then
MsgBox "Masih Ada Data Yang Kosong" Else
Dim SQLEdit As String
SQLEdit = "Update kartusiswa Set Nama= '" & Text2 & "', Jeniskelamin='" & Combo1 & "', alamat='" & Text3 & "',kelas='" & Combo2 & "', Tanggalmasuk='" & DTPicker1 & "' where Nomorinduk='" & Text1 & "'"
Conn.Execute SQLEdit
Call KondisiAwal Form_Activate End If
End If End Sub
Private Sub Cmdsearch_Click() Dim i As String
Dim RS As New ADODB.Recordset
i = InputBox("Silahkan masukkan Nama yang ingin anda cari!", "Search") If i = "" Then
CmdSearch.Visible = True Exit Sub
Else Text1 = i
RS.Open " select* from Kartusiswa where Nama = '" & Text1 & "'", Conn If Not RS.EOF Then
Text1 = RS.Fields(0) Text2 = RS.Fields(1) Combo1 = RS.Fields(2) Text3 = RS.Fields(3) Combo2 = RS.Fields(4) DTPicker1 = RS.Fields(5)
Exit Sub
CmdEdit_Click Else
MsgBox "Data yang anda cari tidak ditemukan....!", vbOKOnly + vbInformation, "Search"
Text1.Text = ""
CmdSearch.Visible = True Exit Sub
End If End If End Sub
Private Sub CmdHapus_Click() Text1 = ""
Text2 = "" Combo1 = "" Text3 = "" Combo2 = ""
pesan = MsgBox("Apakah anda yakin menghapus data ini?", vbYesNo + vbInformation, "Delete")
If pesan = vbNo Then Exit Sub
Else End If End Sub
Select Case CmdTutup.Caption Case "&Tutup"
Unload Me Case "&Batal" TidakSiapIsi KondisiAwal End Select
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then If Len(Text1) < 4 Then
MsgBox "Kode Harus 4 Digit" Text1.SetFocus
Else
Text2.SetFocus End If
If CmdInput.Caption = "SIMPAN" Then Call CariData
If Not RSkartusiswa.EOF Then TampilkanData
MsgBox "Kode kartusiswa Sudah Ada" KosongkanText
Text1.SetFocus Else
Text2.SetFocus End If
End If
If CmdEdit.Caption = "SIMPAN" Then Call CariData
If Not RSkartusiswa.EOF Then TampilkanData
Text1.Enabled = False Text2.SetFocus Else
Text1.SetFocus End If
End If
If CmdHapus.Enabled = True Then Call CariData
If Not RSkartusiswa.EOF Then TampilkanData
pesan = MsgBox("Yakin akan dihapus", vbYesNo) If pesan = vbYes Then
Dim SQLHapus As String
SQLHapus = "Delete From datasiswa where Nama= '" & Text2 & "'" Conn.Execute SQLHapus
Call KondisiAwal DataGrid1.Refresh Adodc1.Refresh Form_Activate CmdHapus.SetFocus Else
Call KondisiAwal Form_Activate CmdHapus.SetFocus End If
Else
MsgBox "Data Tidak ditemukan" Text1.SetFocus
End If End If End If End Sub
Private Sub TEXT2_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then Combo1.SetFocus End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text3.SetFocus
End Sub
Private Sub Text3_Keypress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then Combo2.SetFocus End Sub
Private Sub Combo2_Keypress(KeyAscii As Integer) If KeyAscii = 13 Then
If CmdInput.Enabled = True Then CmdInput.SetFocus
ElseIf CmdEdit.Enabled = True Then CmdEdit.SetFocus
End If End If
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then KeyAscii = 0
End Sub
Function CariGrid() Call BukaDB
'mencari kode datasiswa yang ada dalam grid di kolom 0
RSkartusiswa.Open "Select * From kartusiswa where NoInduk='" & DataGrid1.Columns(0) & "'", Conn
End Function
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode
'jika menekan enter setelah memilih data Case vbKeyReturn
'jika cmdedit caption-nya simpan maka If CmdEdit.Caption = "&Simpan" Then 'panggil prosedur SelectAllVisible1 Call SelectAllVisible1
Text2.SetFocus
Call SelectAllVisible2 End If
Case vbKeyEscape KondisiAwal
CmdHapus.SetFocus End Select
End Sub
Sub SelectAllVisible1()
'jika text1 tidak sama dengan isi grid kolom 0 maka If Text1 <> DataGrid1.Columns(0) Then
'ubah text1 menjadi isi grid kolom 0 (Nomorinduk) Text1 = DataGrid1.Columns(0)
'panggil prosedur caridata Call CariData
'text1 (Nomorinduk) dinonaktifkan Text1.Enabled = False
'pindahkan isi grid kolom 0 ke text1 dan seterusnya Text1 = DataGrid1.Columns(0)
Text2 = DataGrid1.Columns(1) Combo1 = DataGrid1.Columns(2) Text3 = DataGrid1.Columns(3) Combo2 = DataGrid1.Columns(4) Text1.SetFocus
End If End Sub
Sub SelectAllVisible2()
If Text1 <> DataGrid1.Columns(0) Then Text1 = DataGrid1.Columns(0) Call CariData
Text1.Enabled = False
Text2 = DataGrid1.Columns(1)
'jika semua textbox telah terisi dan kode kartusiswa ditemukan 'munculkan pesan penghapusan
'jika dijawab YES If pesan = vbYes Then 'hapus data
Dim SQLHapus As String
SQLHapus = "Delete From kartusiswa where Nama= '" & Text2 & "'" Conn.Execute SQLHapus
Adodc1.Refresh DataGrid1.Refresh
KondisiAwal
CmdHapus.SetFocus Else
'jika dijawab NO kembali ke kondisi awal KondisiAwal
CmdHapus.SetFocus End If
End If End Sub
Private Sub Text2_Change()
Adodc1.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database.mdb"
Adodc1.ConnectionString = Conn.ConnectionString
Adodc1.RecordSource = "select * from kartusiswa where Nama like '%" & Text2 & "%'"
Adodc1.Refresh DataGrid1.Refresh
Set DataGrid1.DataSource = Adodc1 DataGrid1.Refresh
End Sub
Form menu daftar buku
Private Sub CmdGo_Click() If Text1 = "" Then
Else
Dim RS As New ADODB.Recordset Set RS = New ADODB.Recordset
RS.Open " select * From databuku where Kodebuku = '" & Text1 & "'", Conn If Not RS.EOF Then
Text2 = RS.Fields(1) Text3 = RS.Fields(2) Text4 = RS.Fields(3)
Else
MsgBox "Data tidak ditemukan...!", vbOKOnly + vbInformation, "Search" Exit Sub
End If End If
End Sub
Private Sub Form_Activate() Call BukaDB
Adodc1.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database.mdb"
Adodc1.ConnectionString = Conn.ConnectionString
Adodc1.RecordSource = "SELECT * FROM databuku ORDER BY Kodebuku" Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1 DataGrid1.Refresh
End Sub
Function CariData() Call BukaDB
RSdatabuku.Open "Select * From databuku where Kodebuku='" & Text1 & "'", Conn
Private Sub KosongkanText() Text1 = ""
Text2 = "" Text3 = "" Text4 = ""
End Sub
Private Sub SiapIsi() Text1.Enabled = True Text2.Enabled = True Text3.Enabled = True Text4.Enabled = True End Sub
Private Sub TidakSiapIsi() Text1.Enabled = False Text2.Enabled = False Text3.Enabled = False Text4.Enabled = False
End Sub
Private Sub KondisiAwal() KosongkanText
TidakSiapIsi
CmdInput.Caption = "&Input" CmdEdit.Caption = "&Edit" CmdHapus.Caption = "&Hapus" CmdTutup.Caption = "&Tutup" CmdInput.Enabled = True CmdEdit.Enabled = True CmdHapus.Enabled = True End Sub
Private Sub TampilkanData() With RSdatabuku
Text4 = RSdatabuku!Pengarang
End If End With End Sub
Private Sub CmdInput_Click()
If CmdInput.Caption = "&Input" Then CmdInput.Caption = "&Simpan" CmdEdit.Enabled = False
CmdHapus.Enabled = False CmdTutup.Caption = "&Batal" SiapIsi
KosongkanText Text1.SetFocus Else
If Text1 = "" Or Text2 = "" Or Text3 = "" Or Text4 = "" Then MsgBox "Data Belum Lengkap...!"
Else
Dim SQLTambah As String
SQLTambah = "Insert Into databuku (Kodebuku,Judul,Penerbit,Pengarang) values ('" & Text1 & "','" & Text2 & "','" & Text3 & "','" & Text4 & "')"
Conn.Execute SQLTambah Call KondisiAwal
Form_Activate End If
End If End Sub
Private Sub CmdEdit_Click()
If CmdEdit.Caption = "&Edit" Then CmdInput.Enabled = False
CmdEdit.Caption = "&Simpan" CmdHapus.Enabled = False CmdTutup.Caption = "&Batal" SiapIsi
Text1.SetFocus Else
MsgBox "Masih Ada Data Yang Kosong" Else
Dim SQLEdit As String
SQLEdit = "Update databuku Set Judul= '" & Text2 & "', Penerbit='" & Text3 & "', Pengarang='" & Text4 & "' where Kodebuku='" & Text1 & "'"
Conn.Execute SQLEdit Call KondisiAwal Form_Activate End If
End If End Sub
Private Sub Cmdsearch_Click() CmdSearch.Visible = Enabled
Dim i As String
Dim RS As New ADODB.Recordset
i = InputBox("Silahkan masukkan Kode Buku yang ingin anda cari!", "Search") If i = "" Then
CmdSearch.Visible = True Exit Sub
Else Text1 = i
Set RS = New ADODB.Recordset
RS.Open " select*from databuku where Kodebuku = '" & Text1 & "'", Conn If Not RS.EOF Then
Text1 = RS.Fields(0) Text2 = RS.Fields(1) Text3 = RS.Fields(2) Text4 = RS.Fields(3)
Exit Sub
CmdEdit_Click Else
Text1.Text = ""
CmdSearch.Visible = True Exit Sub
End If End If End Sub
Private Sub CmdHapus_Click() Text1 = ""
Text2 = "" Text3 = "" Text4 = ""
pesan = MsgBox("Apakah anda yakin menghapus data ini?", vbYesNo + vbInformation, "Delete")
If pesan = vbNo Then Exit Sub
Else End If End Sub
Private Sub CmdTutup_Click() Select Case CmdTutup.Caption Case "&Tutup"
Unload Me Case "&Batal" TidakSiapIsi KondisiAwal End Select
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If Len(Text1) < 4 Then
MsgBox "Kode Harus 4 Digit" Text1.SetFocus
Else
Text2.SetFocus End If
If CmdInput.Caption = "SIMPAN" Then Call CariData
If Not RSdatasiswa.EOF Then TampilkanData
MsgBox "Kode datasiswa Sudah Ada" KosongkanText
Text1.SetFocus Else
Text2.SetFocus End If
End If
If CmdEdit.Caption = "SIMPAN" Then Call CariData
If Not RSdatasiswa.EOF Then TampilkanData
Text1.Enabled = False Text2.SetFocus Else
MsgBox "Kode datasiswa Tidak Ada" Text1 = ""
Text1.SetFocus End If
End If
If CmdHapus.Enabled = True Then Call CariData
If Not RSdatasiswa.EOF Then TampilkanData
pesan = MsgBox("Yakin akan dihapus", vbYesNo) If pesan = vbYes Then
SQLHapus = "Delete From datasiswa where Kodebuku= '" & Text1 & "'" Conn.Execute SQLHapus
Call KondisiAwal Form_Activate CmdHapus.SetFocus Else
Call KondisiAwal Form_Activate CmdHapus.SetFocus End If
Else
MsgBox "Data Tidak ditemukan" Text1.SetFocus
End If End If End If End Sub
Private Sub TEXT2_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then Text3.SetFocus End Sub
Private Sub Text3_Keypress(KeyAscii As Integer) If KeyAscii = 13 Then Text4.SetFocus
End Sub
Private Sub TEXT4_Keypress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
Function CariGrid() Call BukaDB
RSdatasiswa.Open "Select * From databuku where Kodebuku='" & DataGrid1.Columns(0) & "'", Conn
End Function
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode
'jika menekan enter setelah memilih data Case vbKeyReturn
'jika cmdedit caption-nya simpan maka If CmdEdit.Caption = "&Simpan" Then 'panggil prosedur SelectAllVisible1 Call SelectAllVisible1
Text2.SetFocus
'jika cmdhapus caption-nya hapus maka ElseIf CmdHapus.Caption = "&Hapus" Then 'panggil prosedur SelectAllVisible2 Call SelectAllVisible2
End If
Case vbKeyEscape KondisiAwal
CmdHapus.SetFocus End Select
End Sub
Sub SelectAllVisible1()
'jika text1 tidak sama dengan isi grid kolom 0 maka If Text1 <> DataGrid1.Columns(0) Then
'ubah text1 menjadi isi grid kolom 0 (Kodebuku) Text1 = DataGrid1.Columns(0)
'panggil prosedur caridata Call CariData
'text1 (Kodebuku) dinonaktifkan Text1.Enabled = False
'pindahkan isi grid kolom 0 ke text1 dan seterusnya Text1 = DataGrid1.Columns(0)
Text2 = DataGrid1.Columns(1) Combo1 = DataGrid1.Columns(2) Text3 = DataGrid1.Columns(3) Text1.SetFocus
End Sub
Sub SelectAllVisible2()
If Text1 <> DataGrid1.Columns(0) Then Text1 = DataGrid1.Columns(0) Call CariData
Text1.Enabled = False
'jika semua textbox telah terisi dan kode databuku ditemukan 'munculkan pesan penghapusan
pesan = MsgBox("Yakin akan dihapus..?", vbYesNo, "Konfirmasi") 'jika dijawab YES
If pesan = vbYes Then 'hapus data
Dim SQLHapus As String
SQLHapus = "Delete From databuku where Kodebuku= '" & Text1 & "'" Conn.Execute SQLHapus
DataGrid1.Refresh KondisiAwal
CmdHapus.SetFocus Else
'jika dijawab NO kembali ke kondisi awal KondisiAwal
CmdHapus.SetFocus End If
End If End Sub
Private Sub Text1_Change()
Adodc1.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database.mdb"
Adodc1.ConnectionString = Conn.ConnectionString
Adodc1.RecordSource = "select * from databuku where Kodebuku like '%" & Text1 & "%'"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1 DataGrid1.Refresh