1. Menu Utama
Private Sub abt_Click() frmAbout.Show
End Sub
Private Sub dafAbsenHar_Click() frmDafAbsensiHar.Show
End Sub
Private Sub dafPeg_Click() frmDafPegawai.Show
End Sub
Private Sub dafUser_Click() frmDaftarUser.Show
End Sub
Private Sub FA_Click() frmAbsensi.Show
End Sub
Private Sub FP_Click() frmPegawai1.Show End Sub
Private Sub FU_Click() frmUser.Show
End Sub
Private Sub K_Click() End
End Sub
Private Sub LapAbsensiBul_Click() frmLapAbsensiBul.Show
End Sub
Private Sub LapAbsensiHar_Click() frmLapAbsensiHar.Show
End Sub
Private Sub login_Click() frmLogin.Show
End Sub
Private Sub logout_Click() mnuFile.Enabled = False mnuAbsen.Enabled = False mnuLap.Enabled = False bolLogon = False
End Sub
Private Sub MDIForm_Activate() If bolLogon = True Then
mnuFile.Enabled = False mnuAbsen.Enabled = False mnuLap.Enabled = False End If
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) Select Case Button.Index
Case 1
If bolLogon = True Then frmPegawai1.Show End If
Case 2
If bolLogon = True Then frmAbsensi.Show End If
Case 3 End End Select End Sub
Private Sub Timer1_Timer() If bolLogon = True Then
StatusBar1.Panels(1).Text = "Jam : " & Format(Now, "HH:MM:SS") StatusBar1.Panels(2).Text = "Tanggal :" & Format(Date, _
"d MMMM yyyy")
StatusBar1.Panels(3).Text = "USER ID: " & UserID Else
UserID = ""
StatusBar1.Panels(1).Text = "Jam : " StatusBar1.Panels(2).Text = "Tanggal :" StatusBar1.Panels(3).Text = "USER ID: " End If
End Sub
2. Login
Option Explicit
Dim rsUser As Recordset
Private Sub cmdCancel_Click() Me.Hide
Unload Me End Sub
Private Sub cmdOK_Click() On Error Resume Next UserID = txtUser.Text
Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from [uUser] where UserId='" & _ txtUser.Text & "' and Passwd='" & txtPass.Text & "'", _ CN, adOpenDynamic, adLockOptimistic
If rsCari.EOF = True Then MsgBox "Password salah" txtPass = ""
txtUser = "" bolLogon = False txtUser.SetFocus Else
Me.Hide
MenuUtama.Show End If
End Sub
Private Sub Form_Activate() txtPass = ""
txtUser = "" txtUser.SetFocus End Sub
Private Sub Form_Load() Koneksi
End Sub
Private Sub txtPass_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
cmdOk.Enabled = True cmdOk.SetFocus
End If End Sub
Private Sub txtUser_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
txtPass.Locked = False txtPass.SetFocus
End If End Sub
3. Logout
mnuFile.Enabled = False mnuAbsen.Enabled = False mnuLap.Enabled = False bolLogon = False
4. Data Pegawai
Option Explicit Dim J As ListItem
Dim IDPegawai As Integer Dim bolOk As Boolean
Dim rsPegawai As Recordset Sub CariID()
Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from Pegawai order by IDPegawai desc", CN, 1, 2 If Not rsCari.EOF Then
IDPegawai = rsCari!IDPegawai + 1 Else
IDPegawai = 1 End If
Set rsCari = Nothing
Set rsSimpan = New ADODB.Recordset rsSimpan.Open "Pegawai", CN, 1, 2 rsSimpan.AddNew
rsSimpan!IDPegawai = IDPegawai rsSimpan!StatusRec = "1"
rsSimpan.Update Set rsSimpan = Nothing End Sub
End Sub
Private Sub cboGol_Click() cboJabatan.Enabled = True cboJabatan.SetFocus
End Sub
Private Sub cboJabatan_Click() If Tambah = True Then
cmdSimpan.Enabled = True cmdSimpan.SetFocus
End If End Sub
Private Sub cboJK_Click()
If cboJK.Text = "Laki-Laki" Then Label19.Caption = "Nama Istri" Else
Label19.Caption = "Nama Suami" End If
cboStatusKawin.Enabled = True cboStatusKawin.SetFocus
End Sub
Private Sub cboStatusKawin_Click() If cboStatusKawin.Text = "Kawin" Then txtNmPasangan.Enabled = True txtNmPasangan.SetFocus
Else
txtNmPasangan.Text = "-" txtTempLahir.Enabled = True txtTempLahir.SetFocus
End If End Sub
Private Sub cmdBatal_Click() Call Bersih
Call Mati
cmdTambah.Enabled = True cmdSimpan.Enabled = False cmdCari.Enabled = True cmdEdit.Enabled = False cmdHapus.Enabled = False cmdBatal.Enabled = True cmdTambah.SetFocus End Sub
Private Sub cmdCari_Click() Cari = True
End Sub
Private Sub cmdEdit_Click() cmdEdit.Enabled = False cmdHapus.Enabled = False
If Ubah = True Then
If X = vbYes Then
Timer1.Enabled = True
Set rsUbah = New ADODB.Recordset
Set rsUbah = New ADODB.Recordset
rsUbah.Open "Update Pegawai SET Nama ='" & txtNama.Text _ & "', Alamat='" & txtAlamat.Text & "'," & _
"TglMasuk='" & Format(txtTglMasuk.Value, "dd-mm-yyyy") _ & "',TglLahir='" & Format(txtTglLahir.Value, _
"dd-mm-yyyy") & "'," & _
"noKTP='" & txtNoKTP.Text & "', JK='" & Left(cboJK.Text,_ & "',StatusKawin='" & Left(cboStatusKawin.Text, 1) _ & "'," & _"Nama_Pasangan='" & txtNmPasangan.Text _ & "',Jabatan='" & Left(cboJabatan.Text, 1) & "', _ Gol='" & Left(cboGol.Text, 1) & "', NoTelp='" _
& txtNoTelp.Text & "',NoHP='" & txtNoHP.Text & "'," & _ "TempLahir='" & txtTempLahir.Text & "' where _
IDPegawai =" & IDPegawai & "", CN, 1, 2 Set rsUbah = Nothing
Call Mati Call Bersih Call Segar
cmdTambah.Enabled = True cmdSimpan.Enabled = False cmdCari.Enabled = True cmdEdit.Enabled = False cmdHapus.Enabled = False cmdBatal.Enabled = True cmdTambah.SetFocus
Else
Call Mati Call Bersih Call Segar
cmdTambah.Enabled = True cmdSimpan.Enabled = False cmdCari.Enabled = True cmdEdit.Enabled = False cmdHapus.Enabled = False cmdBatal.Enabled = True cmdTambah.SetFocus End If
End If End Sub
Private Sub cmdHapus_Click() cmdHapus.Enabled = False
Set rsHapus = New ADODB.Recordset
rsHapus.Open "Delete from Pegawai where IDPegawai=" & IDPegawai _ & "", CN, 1, 2
Set rsHapus = Nothing Call Segar
Call Mati Call Bersih
cmdBatal.Enabled = True cmdTambah.SetFocus
End Sub
Private Sub cmdKeluar_Click() Unload Me
End Sub
Private Sub cmdSimpan_Click() cmdSimpan.Enabled = False
X = MsgBox("Data anggota mau disimpan ?", vbYesNo) If X = vbYes Then
If txtNama.Text <> "" Then If IDPegawai <> 0 Then
If txtAlamat.Text <> "" Then If cboJK.Text <> "" Then
If txtTempLahir.Text <> "" Then
If cboStatusKawin.Text <> "" Then If txtNoKTP.Text <> "" Then
If txtNmPasangan.Text <> "" Then If cboJabatan.Text <> "" Then bolOk = True
Else
bolOk = False End If
Else
bolOk = False End If
Else
bolOk = False End If
Else
bolOk = False End If
Else
bolOk = False End If
Else
bolOk = False End If
Else
bolOk = False End If
Else
bolOk = False End If
Else
bolOk = False End If
If bolOk = True Then
Set rsUbah = New ADODB.Recordset
rsUbah.Open "Update Pegawai SET Nama ='" & txtNama.Text & _ "', Alamat='" & txtAlamat.Text & "',NIP='" & txtNIP.Text _
& "'," & _"TglMasuk='" & Format(txtTglMasuk.Value, _ "dd-mm-yyyy")& "',TglLahir='" & Format(txtTglLahir.Value, "dd-mm-yyyy") & "'," & _
& "'," & "Nama_Pasangan='" & txtNmPasangan.Text _ & "',Jabatan='" & Left(cboJabatan.Text, 1) & "',Gol='" _ & Left(cboGol.Text, 1) & "', noTelp='" & txtNoTelp.Text _ & "',NoHP='" & txtNoHP.Text & "'," & "TempLahir='" _ & txtTempLahir.Text & "',StatusRec='*' where IDPegawai _ =" & IDPegawai & "", CN, 1, 2
Set rsUbah = Nothing Call Segar
Call Mati Call Bersih
cmdTambah.Enabled = True cmdSimpan.Enabled = False cmdCari.Enabled = True cmdEdit.Enabled = False cmdHapus.Enabled = False cmdBatal.Enabled = True cmdTambah.SetFocus Else
MsgBox "Data belum lengkap ..." End If
End If End Sub
Private Sub cmdTambah_Click() Tambah = True
Cari = False
cmdTambah.Enabled = False Call CariID
txtTglMasuk.Value = Format(Now, "dd-mm-yyyy") cmdSimpan.Enabled = True
txtNIP.Enabled = True txtNIP.SetFocus
End Sub
Private Sub Form_Activate() Call Mati
Call Bersih Call Segar
cmdTambah.Enabled = True cmdSimpan.Enabled = False cmdCari.Enabled = True cmdEdit.Enabled = False cmdHapus.Enabled = False cmdBatal.Enabled = True cmdTambah.SetFocus
End Sub
Private Sub Form_Load() Call Koneksi
cboStatusKawin.AddItem "Kawin" cboStatusKawin.AddItem "Belum" cboJK.AddItem "Laki-Laki" cboJK.AddItem "Perempuan"
cboJabatan.AddItem "1.Kepala Dinas" cboJabatan.AddItem "2.Kepala Seksi" cboJabatan.AddItem "3.Staff"
cboGol.AddItem "3.III" cboGol.AddItem "4.IV"
End Sub
Private Sub Form_Unload(Cancel As Integer) Call Bersih
End Sub
Private Sub lv1_Click() If Cari = True Then
IDPegawai = lv1.ListItems.Item(lv1.SelectedItem.Index).Text Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from Pegawai where IDPegawai=" & _ IDPegawai & "", CN, adOpenDynamic, adLockOptimistic If Not rsCari.EOF = True Then
txtNama = rsCari!Nama txtNIP = rsCari!NIP
txtAlamat = rsCari!alamat
If rsCari!JK = "L" Then cboJK = "Laki-Laki"
Label19.Caption = "Nama Istri" Else
cboJK = "Perempuan"
Label19.Caption = "Nama Suami" End If
txtTempLahir = rsCari!TempLahir
If rsCari!statuskawin = "K" Then cboStatusKawin = "Kawin" Else
cboStatusKawin = "Belum" End If
txtNoKTP = rsCari!NoKTP
txtNmPasangan = rsCari!Nama_Pasangan txtNoTelp.Text = rsCari!NoTelp
txtNoHP.Text = rsCari!NoHP
If rsCari!jabatan = "1" Then cboJabatan = "1.Kepala Dinas" ElseIf rsCari!jabatan = "2" Then cboJabatan = "2.Kepala Seksi" ElseIf rsCari!jabatan = "3" Then cboJabatan = "3.Staff"
End If
If rsCari!Gol = "1" Then cboGol = "1.I"
ElseIf rsCari!Gol = "2" Then cboGol = "2.II"
ElseIf rsCari!Gol = "3" Then cboGol = "3.III"
Else
cboGol = "4.IV" End If
cmdEdit.Enabled = True cmdHapus.Enabled = True Else
MsgBox "User tidak ada ..." Call Bersih
End If End If
End Sub Sub Segar()
lv1.ListItems.Clear
Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from Pegawai Order by IDPegawai asc", _ CN, 1, 3
If Not rsCari.EOF = True Then Do While Not rsCari.EOF
Set J = lv1.ListItems.Add(, , rsCari!IDPegawai) J.SubItems(1) = rsCari!NIP
J.SubItems(2) = rsCari!TglMasuk J.SubItems(3) = rsCari!Nama J.SubItems(4) = rsCari!alamat J.SubItems(5) = rsCari!NoTelp J.SubItems(6) = rsCari!NoHP J.SubItems(7) = rsCari!NoKTP rsCari.MoveNext
If rsCari.EOF Then Exit Do
End If Loop End If
Set rsCari = Nothing End Sub
Private Sub Timer1_Timer() Frame3.Visible = True
Bar1.Value = Bar1.Value + 10 lblSaving.Caption = Bar1.Value If Bar1.Value = 100 Then
Timer1.Enabled = False Frame3.Visible = False Bar1.Value = 0
End If End Sub
Private Sub txtAlamat_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
txtNoKTP.Enabled = True txtNoKTP.SetFocus
End If End Sub
Private Sub txtNama_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
txtAlamat.Enabled = True txtAlamat.SetFocus
End If End Sub
Sub Mati()
txtNama.Enabled = False txtAlamat.Enabled = False cboJK.Enabled = False
txtTempLahir.Enabled = False txtTglLahir.Enabled = False cboStatusKawin.Enabled = False txtNoKTP.Enabled = False
txtNoTelp.Enabled = False txtNoHP.Enabled = False
txtNmPasangan.Enabled = False cboJabatan.Enabled = False cboGol.Enabled = False txtTglMasuk.Enabled = False End Sub
Sub Hidup()
txtNIP.Enabled = True txtNama.Enabled = True txtAlamat.Enabled = True cboJK.Enabled = True
txtTempLahir.Enabled = True txtTglLahir.Enabled = True cboStatusKawin.Enabled = True txtNoKTP.Enabled = True
txtNoTelp.Enabled = True txtNoHP.Enabled = True
txtNmPasangan.Enabled = True cboJabatan.Enabled = True cboGol.Enabled = True txtTglMasuk.Enabled = True
End Sub
Sub Bersih() txtNama = "" IDPegawai = 0 txtNIP = "" txtAlamat = "" cboJK = ""
txtTempLahir = "" cboStatusKawin = "" txtNoKTP = ""
txtNmPasangan = "" txtNoTelp = "" txtNoHP = ""
cboJabatan.Text = "" cboGol.Text = ""
txtTglMasuk.Value = Format(Now, "dd-mm-yyyy") txtTglLahir.Value = Format(Now, "dd-mm-yyyy") Cari = False
Tambah = False
Set rsHapus = New ADODB.Recordset
rsHapus.Open "Delete from Pegawai where StatusRec='1'", CN, 1, 2 Set rsHapus = Nothing
End Sub
txtTglMasuk.Enabled = True txtTglMasuk.SetFocus
End If
End Sub
Private Sub txtNmPasangan_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
txtTempLahir.Enabled = True txtTempLahir.SetFocus
End If End Sub
Private Sub txtNoHP_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
cboJK.Enabled = True cboJK.SetFocus
End If
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii _ = vbKeyBack Or KeyAscii = Asc(".") Or KeyAscii = 13) Then Beep
MsgBox "Isi dengan angka 0-9" KeyAscii = 0
End If End Sub
Private Sub txtnoKTP_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
txtNoTelp.Enabled = True txtNoTelp.SetFocus
End If
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii _ = vbKeyBack Or KeyAscii = Asc(".") Or KeyAscii = 13) Then Beep
MsgBox "Isi dengan angka 0-9" KeyAscii = 0
End If End Sub
Private Sub txtNoTelp_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
txtNoHP.Enabled = True txtNoHP.SetFocus
End If
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii _ = vbKeyBack Or KeyAscii = Asc(".") Or KeyAscii = 13) Then Beep
MsgBox "Isi dengan angka 0-9" KeyAscii = 0
End If End Sub
Private Sub txtTempLahir_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
txtTglLahir.Enabled = True txtTglLahir.SetFocus
End If End Sub
cboGol.SetFocus End Sub
Private Sub txtTglMasuk_Click() txtNama.Enabled = True
txtNama.SetFocus End Sub
5. Daftar Pegawai
Private Sub Form_Activate() Me.WindowState = 2
cr.ReportFileName = App.Path & "\Laporan\RepDafPegawai.rpt" cr.RetrieveDataFiles
cr.Connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _ & App.Path & "\dbPegawai.mdb;Persist Security Info=False" cr.WindowShowRefreshBtn = True
cr.PrintReport
cr.WindowState = crptMaximized cr.Action = 1
End Sub
6. Data User
Option Explicit Dim J As ListItem
Dim rsUser As Recordset Dim UserID As String
Private Sub cmdBatal_Click() Mati
Bersih
Ubah = False Tambah = False Cari = False
cmdUpdate.Enabled = False cmdHapus.Enabled = False cmdCari.Enabled = True cmdTambah.Enabled = True cmdTambah.SetFocus
End Sub
Private Sub cmdCari_Click() Cari = True
End Sub
Private Sub cmdCetak_Click() frmDaftarUser.Show
End Sub
Private Sub cmdHapus_Click() rsCari.Delete
Set rsCari = Nothing Mati
Bersih Segar
cmdHapus.Enabled = False cmdCari.Enabled = True cmdSimpan.Enabled = False cmdTambah.Enabled = True cmdTambah.SetFocus
End Sub
Private Sub cmdKeluar_Click() Unload Me
End Sub
Private Sub cmdSimpan_Click() If Tambah = True Then
Call Save End If
End Sub
Private Sub cmdTambah_Click() Tambah = True
cmdTambah.Enabled = False cmdSimpan.Visible = True cmdCari.Enabled = False cmdCari.Enabled = False txtUserID.Enabled = True txtUserID.SetFocus
End Sub
Private Sub cmdUpdate_Click() If Ubah = True Then
Set rsUbah = New ADODB.Recordset
rsUbah.Open "Update [UUser] Set Passwd ='" & txtPasswd.Text _ & "'where UserID ='" & txtUserID.Text & "'", CN, _
adOpenDynamic, adLockOptimistic MsgBox "Data sudah Ubah" Ubah = False
Mati Bersih Segar
Set rsUbah = Nothing
cmdUpdate.Enabled = False cmdHapus.Enabled = False cmdCari.Enabled = True cmdSimpan.Enabled = False cmdTambah.Enabled = True cmdTambah.SetFocus
End If End Sub
Private Sub Form_Activate() Cari = False
Call Segar Mati
Bersih
cmdTambah.SetFocus End Sub
Sub Mati()
txtUserID.Enabled = False txtPasswd.Enabled = False End Sub
Sub Bersih()
txtUserID.Text = "" txtPasswd.Text = "" Ubah = False
Tambah = False UserID = "" End Sub
Private Sub Form_Load() Koneksi
End Sub
Private Sub lv_Click() On Error Resume Next If Cari = True Then
UserID = lv.ListItems.Item(lv.SelectedItem.Index).Text Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from [uUser] where UserID='" & UserID _ & "'", CN, adOpenDynamic, adLockOptimistic
If Not rsCari.EOF = True Then txtUserID.Text = UserID
txtPasswd.Text = rsCari!Passwd Ubah = True
cmdUpdate.Enabled = True cmdHapus.Enabled = True txtPasswd.Enabled = True txtPasswd.SetFocus
Else
MsgBox "User tidak ada ..." txtUserID.Text = ""
txtPasswd.Text = "" End If
End If End Sub
Private Sub txtPasswd_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
If Tambah = True Then
cmdSimpan.Enabled = True cmdTambah.Enabled = False cmdSimpan.SetFocus
ElseIf Ubah = True Then cmdUpdate.Enabled = True cmdUpdate.SetFocus
End If End If End Sub
Sub Save()
rsUser.Open "Select * from [uUser] where UserID='" _
& txtUserID.Text & "' and Passwd='" & txtPasswd.Text & "'", _ CN, adOpenDynamic, adLockOptimistic
If Tambah = True Then
If rsUser.EOF = True Then
Set rsSimpan = New ADODB.Recordset
rsSimpan.Open "select * from [uUser]", _ CN, adOpenDynamic, adLockOptimistic rsSimpan.AddNew
rsSimpan.Fields("UserID") = txtUserID.Text rsSimpan.Fields("Passwd") = txtPasswd.Text rsSimpan.Update
Mati Bersih Segar
MsgBox "Data sudah tersimpan" Tambah = False
cmdUpdate.Enabled = False cmdHapus.Enabled = False cmdCari.Enabled = True cmdSimpan.Enabled = False cmdTambah.Enabled = True cmdTambah.SetFocus
Else
MsgBox "User sudah ada ..." txtPasswd.Text = ""
txtUserID.Text = "" txtUserID.SetFocus End If
End If
End Sub Sub Segar()
lv.ListItems.Clear
Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from uUser Order by UserID asc", CN, 1, 3 If Not rsCari.EOF = True Then
Do While Not rsCari.EOF
Set J = lv.ListItems.Add(, , rsCari!UserID) J.SubItems(1) = rsCari!Passwd
rsCari.MoveNext If rsCari.EOF Then Exit Do
End If Loop End If
Set rsCari = Nothing End Sub
Private Sub txtUserId_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
If Tambah = True Then
Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from [uUser] where UserID='" _ & txtUserID.Text & "'", CN, 1,2
If rsCari.EOF = True Then txtPasswd.Enabled = True txtPasswd.SetFocus
Else
txtPasswd.Text = "" txtUserID.SetFocus End If
ElseIf Cari = True Then
Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from [uUser] where UserID='" &_ txtUserID.Text & "'", CN, 1, 2
If rsCari.EOF = True Then
MsgBox "User belum ada ..." txtUserID.Text = ""
txtUserID.SetFocus Else
txtPasswd.Text = rsCari.Fields("Passwd") cmdUpdate.Enabled = True
cmdHapus.Enabled = True cmdUpdate.SetFocus End If
End If End If End Sub
7. Daftar User
Private Sub Form_Activate() Me.WindowState = 2
cr.ReportFileName = App.Path & "\Laporan\RepDafUser.rpt" cr.RetrieveDataFiles
cr.Connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _ App.Path & "\dbPegawai.mdb;Persist Security Info=False" cr.WindowShowRefreshBtn = True
cr.PrintReport
cr.WindowState = crptMaximized cr.Action = 1
End Sub
8. Data Absensi
Option Explicit Dim J As ListItem
Dim IDAbsensi As Integer Dim IDDAbsensi As Integer Dim rsAbsensi As Recordset Dim rsDAbsensi As Recordset Dim IDPegawai As Integer Dim Lama As Integer Dim bolHadir As Boolean Dim Ket As String
Dim bolOk As Boolean Sub Bersih()
bolOk = False Ket = "Ada" IDAbsensi = 0 IDDAbsensi = 0 lblIDD.Caption = "" lblID = ""
txtJamMasuk = "__:__" txtJamPulang = "__:__" lblLama = ""
Cari = False Tambah = False bolHadir = False
Set rsHapus = New ADODB.Recordset
rsHapus.Open "Delete from Absensi where StatusRec='1'", CN, 1, 2 Set rsHapus = Nothing
Set rsHapus = New ADODB.Recordset
rsHapus.Open "Delete from DAbsensi where StatusRec='1'", CN, 1, 2 Set rsHapus = Nothing
End Sub Sub Mati()
cboKode.Enabled = False cboKet.Enabled = False txtJamMasuk.Enabled = False txtJamPulang.Enabled = False txtTgl.Enabled = False
End Sub Sub CariID()
Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from Absensi order by IDAbsensi desc", CN, 1, 2 If Not rsCari.EOF Then
IDAbsensi = rsCari!IDAbsensi + 1 Else
IDAbsensi = 1 End If
Set rsCari = Nothing lblID.Caption = IDAbsensi
Set rsSimpan = New ADODB.Recordset rsSimpan.Open "Absensi", CN, 1, 2 rsSimpan.AddNew
rsSimpan!IDAbsensi = IDAbsensi
rsSimpan!TglAbsen = Format(txtTgl.Value, "dd-mm-yyyy") rsSimpan!StatusRec = "1"
rsSimpan.Update Set rsSimpan = Nothing
End Sub
Sub CariIDD()
Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from DAbsensi order by IDDAbsensi desc", _ CN,1, 2
If Not rsCari.EOF Then
IDDAbsensi = rsCari!IDAbsensi + 1 Else
IDDAbsensi = 1 End If
Set rsCari = Nothing
lblIDD.Caption = IDDAbsensi
rsSimpan.AddNew
rsSimpan!IDDAbsensi = IDDAbsensi rsSimpan!IDAbsensi = IDAbsensi rsSimpan!StatusRec = "1"
rsSimpan.Update Set rsSimpan = Nothing
End Sub
Private Sub cboKet_Click() If bolHadir = False Then cmdSimpan.Enabled = True cmdSimpan.SetFocus
End If End Sub
Private Sub cboKode_Click() If cboKode.Text = "Hadir" Then bolHadir = True
Call CariIDD
cboKet.Text = "Masuk" txtJamMasuk.Enabled = True txtJamMasuk.SetFocus
Else
bolHadir = False cboKet.Enabled = True cboKet.SetFocus
End If End Sub
Private Sub cmdBatal_Click() Call Bersih
Call Mati
cmdTambah.Enabled = True cmdSimpan.Enabled = False cmdCari.Enabled = True cmdEdit.Enabled = False cmdHapus.Enabled = False cmdBatal.Enabled = True cmdTambah.SetFocus End Sub
Private Sub cmdCari_Click() Cari = True
End Sub
Private Sub cmdHapus_Click() cmdHapus.Enabled = False cmdEdit.Enabled = False
Set rsHapus = New ADODB.Recordset
rsHapus.Open "Delete from DAbsensi where IDAbsensi=" & _ IDAbsensi & "", CN, 1, 2
Set rsHapus = Nothing
Set rsHapus = New ADODB.Recordset
rsHapus.Open "Delete from Absensi where IDAbsensi=" & IDAbsensi _ & "", CN, 1, 2
Call Bersih Call SegarPeg Call SegarAbsen
cmdTambah.Enabled = True cmdSimpan.Enabled = False cmdCari.Enabled = True cmdEdit.Enabled = False cmdHapus.Enabled = False cmdBatal.Enabled = True cmdTambah.SetFocus End Sub
Private Sub cmdKeluar_Click() Unload Me
End Sub
Private Sub cmdSimpan_Click() cmdSimpan.Enabled = False
X = MsgBox("Data absensi mau disimpan ?", vbYesNo) If X = vbYes Then
If lblNip.Caption <> "" Then If IDPegawai <> 0 Then If IDAbsensi <> 0 Then bolOk = True
Else
bolOk = False End If
Else
bolOk = False End If
Else
bolOk = False End If
If bolOk = True And bolHadir = True Then Set rsUbah = New ADODB.Recordset
rsUbah.Open "Update Absensi SET IDPegawai=" & IDPegawai _ & ",Kode ='" & Left(cboKode.Text, 1) & "', Keterangan='" _
& Left(cboKet.Text, 1) & "',StatusRec='*' " & _ "where IDAbsensi =" & IDAbsensi & "", CN, 1, 2 Set rsUbah = Nothing
Set rsUbah = New ADODB.Recordset
rsUbah.Open "Update DAbsensi SET JamMasuk ='" _
& txtJamMasuk.Text & "', JamPulang='" & txtJamPulang.Text _ & "',Lama=" & Lama & ",StatusRec='*' " & _
"where IDdAbsensi =" & IDDAbsensi & "", CN, 1, 2 Set rsUbah = Nothing
ElseIf bolOk = True And bolHadir = False Then Set rsUbah = New ADODB.Recordset
rsUbah.Open "Update Absensi SET IDPegawai=" & IDPegawai _ & ",Kode ='" & Left(cboKode.Text, 1) & "', Keterangan='" _ & Left(cboKet.Text, 1) & "',StatusRec='*' " & _
"where IDAbsensi =" & IDAbsensi & "", CN, 1, 2 Set rsUbah = Nothing
End If
Call Bersih
cmdTambah.Enabled = True cmdSimpan.Enabled = False cmdCari.Enabled = True cmdEdit.Enabled = False cmdHapus.Enabled = False cmdBatal.Enabled = True cmdTambah.SetFocus Else
MsgBox "Data belum lengkap ..." End If
Call SegarAbsen End Sub
Private Sub cmdTambah_Click() Tambah = True
Cari = False
cmdTambah.Enabled = False Call CariID
txtTgl.Value = Format(Now, "dd-mm-yyyy") cmdSimpan.Enabled = True
txtTgl.Enabled = True txtTgl.SetFocus
End Sub
Private Sub Form_Activate() Call Mati
Call Bersih Call SegarPeg Call SegarAbsen
cmdTambah.Enabled = True cmdSimpan.Enabled = False cmdCari.Enabled = True cmdEdit.Enabled = False cmdHapus.Enabled = False cmdBatal.Enabled = True cmdTambah.SetFocus End Sub
Private Sub Form_Load() Call Koneksi
cboKode.AddItem "Hadir"
cboKode.AddItem "Tidak Hadir" cboKet.AddItem "Masuk"
cboKet.AddItem "Sakit" cboKet.AddItem "Izin"
cboKet.AddItem "Tidak Ada Pemberitahuan" End Sub
Private Sub lv1_Click() If Cari = True Then
IDAbsensi = lv1.ListItems.Item(lv1.SelectedItem.Index).Text lblID.Caption = IDAbsensi
Set rsAbsensi = New ADODB.Recordset
rsAbsensi.Open "Select * from Absensi where IDAbsensi=" _ & IDAbsensi & "", CN, 1, 2
Ket = "Ada" IDAbsensi = 0 IDDAbsensi = 0 lblID = "" lblNip = "" lblNama = "" cboKode = "" cboKet = ""
txtJamMasuk = "__:__" txtJamPulang = "__:__" lblLama = ""
MsgBox "Absensi tidak ada" Else
txtTgl.Value = Format(rsAbsensi!TglAbsen, "dd-mm-yyyy") IDPegawai = rsAbsensi!IDPegawai
Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from Pegawai where IDPegawai="_ & IDPegawai & "", CN, adOpenDynamic, adLockOptimistic If Not rsCari.EOF = True Then
lblNama = rsCari!Nama lblNip = rsCari!NIP cboKode.Enabled = True cboKode.SetFocus
Else
lblNama = "" lblNip = "" End If
Set rsCari = Nothing
If rsAbsensi!Kode = "H" Then bolHadir = True
cboKode.Text = "Hadir" Else
bolHadir = False
cboKode.Text = "Tidak Hadir" End If
If rsAbsensi!Keterangan = "M" Then cboKet.Text = "Masuk"
ElseIf rsAbsensi!Keterangan = "S" Then cboKet.Text = "Sakit"
ElseIf rsAbsensi!Keterangan = "I" Then cboKet.Text = "Izin"
Else
cboKet.Text = "Tidak Ada Pemberitahuan" End If
If bolHadir = True Then
Set rsDAbsensi = New ADODB.Recordset
rsDAbsensi.Open "Select * from DAbsensi _
where IDAbsensi=" & IDAbsensi & "", CN, 1, 2 If Not rsDAbsensi.EOF = True Then
IDDAbsensi = rsDAbsensi!IDDAbsensi lblIDD.Caption = IDDAbsensi
txtJamMasuk.Text = rsDAbsensi!JamMasuk _ txtJamPulang.Text = rsDAbsensi!JamPulang lblLama.Caption = rsDAbsensi!Lama
Else
lblIDD.Caption = ""
txtJamMasuk.Text = "__:__" txtJamPulang.Text = "__:__" lblLama.Caption = ""
End If
Set rsDAbsensi = Nothing Else
IDDAbsensi = 0 lblIDD.Caption = ""
txtJamMasuk.Text = "__:__" txtJamPulang.Text = "__:__" lblLama.Caption = ""
End If
cmdEdit.Enabled = True cmdHapus.Enabled = True End If
Set rsAbsensi = Nothing End If
End Sub
Private Sub lvPegawai_Click() If Tambah = True Then
IDPegawai = _
lvPegawai.ListItems.Item(lvPegawai.SelectedItem.Index).Text Set rsAbsensi = New ADODB.Recordset
rsAbsensi.Open "Select * from Absensi where IDPegawai=" _ & IDPegawai & " and TglAbsen=#" & _
Format(txtTgl.Value, "yyyy,mm,dd") & "#", CN, 1, 2 If Not rsAbsensi.EOF = True Then
MsgBox "Pegawai ini sudah melakukan absensi" Else
Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from Pegawai where IDPegawai=" _ & IDPegawai & "", CN, adOpenDynamic, adLockOptimistic If Not rsCari.EOF = True Then
lblNama = rsCari!Nama lblNip = rsCari!NIP cboKode.Enabled = True cboKode.SetFocus
Else
lblNama = "" lblNip = "" End If
Set rsCari = Nothing End If
Set rsAbsensi = Nothing End If
End Sub
Private Sub txtJamMasuk_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
txtJamPulang.Enabled = True txtJamPulang.SetFocus
End If End Sub
Sub SegarPeg()
Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from Pegawai Order by IDPegawai asc", _ CN, 1, 3
If Not rsCari.EOF = True Then Do While Not rsCari.EOF
Set J = lvPegawai.ListItems.Add(, , rsCari!IDPegawai) J.SubItems(1) = rsCari!NIP
J.SubItems(2) = rsCari!TglMasuk J.SubItems(3) = rsCari!Nama J.SubItems(4) = rsCari!alamat J.SubItems(5) = rsCari!NoTelp J.SubItems(6) = rsCari!NoHP J.SubItems(7) = rsCari!NoKTP rsCari.MoveNext
If rsCari.EOF Then Exit Do
End If Loop End If
Set rsCari = Nothing End Sub
Sub SegarAbsen() lv1.ListItems.Clear
Set rsAbsensi = New ADODB.Recordset
rsAbsensi.Open "Select * from Absensi Order by IDAbsensi _ asc", CN, 1, 2
If Not rsAbsensi.EOF = True Then Do While Not rsAbsensi.EOF IDPegawai = rsAbsensi!IDPegawai IDAbsensi = rsAbsensi!IDAbsensi Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from Pegawai Where IDPegawai=" _ & IDPegawai & "", CN, 1, 3
If Not rsCari.EOF = True Then
Set J = lv1.ListItems.Add(, , IDAbsensi) J.SubItems(1) = rsAbsensi!TglAbsen
J.SubItems(2) = rsCari!NIP J.SubItems(3) = rsCari!Nama If rsAbsensi!Kode = "H" Then J.SubItems(4) = "Hadir" Else
J.SubItems(4) = "Tidak Hadir" End If
If rsAbsensi!Keterangan = "M" Then J.SubItems(5) = "Masuk"
ElseIf rsAbsensi!Keterangan = "S" Then J.SubItems(5) = "Sakit"
ElseIf rsAbsensi!Keterangan = "I" Then J.SubItems(5) = "Izin"
Else
J.SubItems(5) = "Tidak Ada Pemberitahuan" End If
End If
Set rsCari = Nothing
Exit Do End If Loop End If
Set rsAbsensi = Nothing End Sub
Private Sub txtJamPulang_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
Lama = DateDiff("h", txtJamMasuk.Text, txtJamPulang.Text) lblLama.Caption = Lama
cmdSimpan.Enabled = True cmdSimpan.SetFocus
End If End Sub
9. Daftar Absensi
Private Sub cmdCetak_Click() Call cetak
End Sub
Private Sub cmdKeluar_Click() Unload Me
End Sub
Private Sub Form_Activate()
txtTgl.Value = Format(Now, "dd-mm-yyyy") txtTgl.SetFocus
End Sub Sub cetak()
Me.WindowState = 2
cr.ReportFileName = App.Path & "\Laporan\crDafAbsensiHar.rpt" cr.RetrieveDataFiles
cr.Connect = "Provider=Microsoft.Jet.OLEDB.4.0; _
Data Source=" & App.Path & "\dbPegawai.mdb;Persist _ Security Info=False"
cr.SelectionFormula = "({Absensi.TglAbsen})=date(" & _ Format(CDate(txtTgl.Value), "yyyy,mm,dd") & ")" cr.WindowShowRefreshBtn = True
cr.Formulas(0) = "Tgl='" & txtTgl.Value & "'" cr.PrintReport
cr.WindowState = crptMaximized cr.Action = 1
End Sub
Private Sub Form_Load() Call Koneksi
End Sub
Private Sub txtTgl_Click()
txtTgl.Value = Format(txtTgl.Value, "dd-mm-yyyy") Call Cekdata
End Sub
txtTgl.Text = Format(txtTgl.Value, "dd-mm-yyyy") Call Cekdata
End If End Sub
Private Sub txtTgl_LostFocus() On Error GoTo SalahTanggal
CekTanggal = Format(CDate(txtTgl.Value), "dd-mm-yyyy") On Error GoTo 0
Exit Sub SalahTanggal:
If Len(Trim(txtTgl.Value)) = 0 Then Exit Sub
End If
X = MsgBox("Format tanggal: dd-mm-yyyy" & Chr(13) & _ "Misalnya: 12-01-2013", vbOKOnly)
txtTgl.Enabled = True txtTgl.SetFocus
End Sub
Sub Cekdata()
Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from Absensi where TglAbsen =#" _ & Format(txtTgl.Value, "yyyy-mm-dd") & "#", CN, 1, 2 If Not rsCari.EOF = True Then
cmdCetak.Enabled = True cmdCetak.SetFocus
Else
MsgBox "Data tidak ada " txtTgl.SetFocus
End If
End Sub
10. Laporan Absensi Harian
Private Sub cmdCetak_Click() Call cetak
End Sub
Private Sub cmdKeluar_Click() Unload Me
End Sub
Private Sub Form_Activate()
txtTgl.Value = Format(Now, "dd-mm-yyyy") txtTgl.SetFocus
End Sub
Sub cetak()
Me.WindowState = 2
cr.ReportFileName = App.Path & "\Laporan\crLapAbsensiHar.rpt" cr.RetrieveDataFiles
cr.Connect = "Provider=Microsoft.Jet.OLEDB.4.0; _ Data Source=" & App.Path & "\dbPegawai.mdb;Persist _
Security Info=False"
cr.SelectionFormula = "({Absensi.TglAbsen})=date(" & _ Format(CDate(txtTgl.Value), "yyyy,mm,dd") & ")"
cr.WindowShowRefreshBtn = True
cr.PrintReport
cr.WindowState = crptMaximized r.Action = 1
End Sub
Private Sub Form_Load() Call Koneksi
End Sub
Private Sub txtTgl_Click()
txtTgl.Value = Format(txtTgl.Value, "dd-mm-yyyy") Call Cekdata
End Sub
Private Sub txtTgl_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
txtTgl.Text = Format(txtTgl.Value, "dd-mm-yyyy") Call Cekdata
End If End Sub
Private Sub txtTgl_LostFocus() On Error GoTo SalahTanggal
CekTanggal = Format(CDate(txtTgl.Value), "dd-mm-yyyy") On Error GoTo 0
Exit Sub SalahTanggal:
If Len(Trim(txtTgl.Value)) = 0 Then Exit Sub
End If
X = MsgBox("Format tanggal: dd-mm-yyyy" & Chr(13) & _ "Misalnya: 12-01-2013", vbOKOnly)
txtTgl.Enabled = True txtTgl.SetFocus
End Sub
Sub Cekdata()
Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from Absensi where TglAbsen =#" _ & Format(txtTgl.Value, "yyyy-mm-dd") & "#", CN, 1, 2 If Not rsCari.EOF = True Then
cmdCetak.Enabled = True cmdCetak.SetFocus
Else
MsgBox "Data tidak ada " txtTgl.SetFocus
End If
End Sub
11. Laporan Absensi Bulanan
Option Explicit
Dim Bln As Integer, Thn As Integer Private Sub cboBln_Click()
If cboBln.Text = "Januari" Then Bln = 1
ElseIf cboBln.Text = "Maret" Then Bln = 3
ElseIf cboBln.Text = "April" Then Bln = 4
ElseIf cboBln.Text = "Mei" Then Bln = 5
ElseIf cboBln.Text = "Juni" Then Bln = 6
ElseIf cboBln.Text = "Juli" Then Bln = 7
ElseIf cboBln.Text = "Agustus" Then Bln = 8
ElseIf cboBln.Text = "September" Then Bln = 9
ElseIf cboBln.Text = "Oktober" Then Bln = 10
ElseIf cboBln.Text = "Nopember" Then Bln = 11
ElseIf cboBln.Text = "Desember" Then Bln = 12
End If Call Cari End Sub
Sub Cari()
Set rsCari = New ADODB.Recordset
rsCari.Open "Select * from Absensi where month(TglAbsen)=" _ & Bln & " and year(TglAbsen)=" & txtThn.Text & "", CN, 1, 2 If Not rsCari.EOF Then
cmdCetak.Enabled = True cmdCetak.SetFocus
Else
MsgBox "Data tidak ada" End If
Set rsCari = Nothing End Sub
Sub cetak()
Me.WindowState = 2
cr.ReportFileName = App.Path & "\Laporan\crLapAbsensiBul.rpt" cr.RetrieveDataFiles
cr.Connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _ App.Path & "\dbPegawai.mdb;Persist Security Info=False"
cr.SelectionFormula = "year({Absensi.TglAbsen})=" & _ txtThn.Text & " and month({Absensi.TglAbsen})=" & Bln & "" cr.WindowShowRefreshBtn = True
cr.Formulas(0) = "nmBln='" & cboBln.Text & "'" cr.Formulas(1) = "Thn='" & txtThn.Text & "'" cr.PrintReport
cr.WindowState = crptMaximized cr.Action = 1
End Sub
Private Sub cmdCetak_Click() Call cetak
End Sub
End Sub
Private Sub Form_Activate() txtThn.SetFocus
End Sub
Private Sub Form_Load() Call Koneksi
cboBln.AddItem "Januari" cboBln.AddItem "Pebruari" cboBln.AddItem "Maret" cboBln.AddItem "April" cboBln.AddItem "Mei" cboBln.AddItem "Juni" cboBln.AddItem "Juli" cboBln.AddItem "Agustus" cboBln.AddItem "September" cboBln.AddItem "Oktober" cboBln.AddItem "Nopember" cboBln.AddItem "Desember" End Sub
Private Sub Form_Unload(Cancel As Integer) Unload Me
End Sub
Private Sub txtThn_Change() If Len(txtThn.Text) < 4 Then Exit Sub
Else
cboBln.Enabled = True cboBln.SetFocus