Aplikasi data penduduk

of 19 /19
Siang gan,, untuk mengisi waktu luang bulan puasa ini,, marilah kita berkarya sambil belajar,, Ok,, Disini saya mencoba membuat program data penduduk denagn menggunakan VB 6.0. database nya kita gunakan Acces,, Ok gan,,, Pertama-tama kita rancang desain file nya terlebih dahulu, dengan Nama Table : Penduduk.mdb. Selengkap nya lihat Gambar di bawah ini.. dengan table KTP nya seperti ini.. Jadikan NIK sebagai Key Nya..

Transcript of Aplikasi data penduduk

Siang gan,, untuk mengisi waktu luang bulan puasa ini,, marilah kita berkarya sambil belajar,,

Ok,, Disini saya mencoba membuat program data penduduk denagn menggunakan VB 6.0. database nya kita gunakan Acces,, Ok gan,,,

Pertama-tama kita rancang desain file nya terlebih dahulu, dengan 

Nama Table  : Penduduk.mdb.

Selengkap nya lihat Gambar di bawah ini..

 

 

dengan table KTP nya seperti ini..

Jadikan NIK sebagai Key Nya..

 

 lanjut kan dengan table KK dan Transaksi nya sendiri ya.. hehe..

Kemudian Buka Vb 6.0,, Lalu kita rancang Form

KTP nya seperti gambar dibawah ini..

Coding nya..

Dim tambah As Boolean

Sub Aktif()TxtNIK.Enabled = TrueTxtNama.Enabled = TrueCboJekel.Enabled = TrueTxtTempat.Enabled = TrueTxtTgl.Enabled = TrueTxtAlamat.Enabled = TrueTxtAgama.Enabled = TrueTxtPekerjaan.Enabled = TrueCboStatus.Enabled = TrueEnd Sub

Sub Nonaktif()TxtNIK.Enabled = FalseTxtNama.Enabled = FalseCboJekel.Enabled = FalseTxtTempat.Enabled = FalseTxtTgl.Enabled = FalseTxtAlamat.Enabled = False

TxtAgama.Enabled = FalseTxtPekerjaan.Enabled = FalseCboStatus.Enabled = FalseEnd Sub

Sub Bersih()TxtNIK = ""TxtNama = ""CboJekel = ""TxtTempat = ""TxtAlamat = ""TxtAgama = ""TxtPekerjaan = ""CboStatus = ""End Sub

Sub Tampil()TxtNIK.Text = dbKTP.Recordset!NIKTxtNama.Text = dbKTP.Recordset!NamaCboJekel.Text = dbKTP.Recordset!JekelTxtTempat.Text = dbKTP.Recordset!Tmp_LahirTxtTgl.Value = dbKTP.Recordset!Tgl_LahirTxtAlamat.Text = dbKTP.Recordset!AlamatTxtAgama.Text = dbKTP.Recordset!AgamaTxtPekerjaan.Text = dbKTP.Recordset!PekerjaanCboStatus.Text = dbKTP.Recordset!StatusEnd Sub

Private Sub CboTambah_Click()

End Sub

Private Sub CmdBatal_Click()BersihNonaktifEnd Sub

Private Sub Form_Activate()Call NonaktifCmdSimpan.Enabled = FalseEnd Sub Private Sub CmdTambah_Click()tambah = TrueCall AktifCmdSimpan.Enabled = TrueCall BersihTxtNIK.SetFocusEnd Sub

Private Sub CmdSimpan_Click()If TxtNIK = "" Or TxtNama = "" Or CboJekel = "" Or TxtTempat = "" Or TxtTgl = 0 Or TxtAlamat = "" Or TxtAgama = "" Or Pen = "" Or TxtPekerjaan = "" Or CboStatus = "" ThenMsgBox "Data harus lengkap!", vbExclamation + vbOKOnly, "Info"Exit SubEnd IfWith dbKTP.RecordsetIf tambah = True Then.AddNew!NIK = TxtNIK.Text!Nama = TxtNama.Text!Jekel = CboJekel.Text!Tmp_Lahir = TxtTempat.Text!Tgl_Lahir = TxtTgl.Value!Alamat = TxtAlamat.Text!Agama = TxtAgama.Text!Pekerjaan = TxtPekerjaan.Text!Status = CboStatus.Text.UpdateElse!Nama = TxtNama.Text!Jekel = CboJekel.Text!Tmp_Lahir = TxtTempat.Text!Tgl_Lahir = TxtTgl.Value!Alamat = TxtAlamat.Text!Agama = TxtAgama.Text!Pekerjaan = TxtPekerjaan.Text!Status = CboStatus.Text.UpdateEnd IfEnd WithMsgBox "Data sudah di simpan!", vbInformation + vbOKOnly, "Info"End Sub

Private Sub CmdKoreksi_Click()Dim edit As Stringedit = InputBox("Masukkan NIK..", "Edit", "")dbKTP.Recordset.Find "NIK='" & edit & "'", , adSearchForward, 1If dbKTP.Recordset.EOF Then    MsgBox "Record Kosong", vbInformation, ""    Exit SubElse    tambah = False    Call Aktif    Call Tampil    CmdSimpan.Enabled = TrueEnd IfEnd Sub Private Sub CmdCari_Click()

Dim cari As Stringcari = InputBox("Masukan NIK", "cari", "")dbKTP.Recordset.Find "NIK='" & cari & "'", , adSearchForward, 1If dbKTP.Recordset.EOF ThenMsgBox "data tidak di temukan", vbInformation, "cari"ElseCall TampilExit SubEnd IfEnd Sub

Private Sub CmdHapus_Click()Call BersihX = MsgBox("Yakin data ini akan di hapus?", vbOKCancel + vbExclamation, "Hapus")If X = vbOK ThendbKTP.Recordset.DeleteMsgBox "Data sudah di hapus!", vbInformation, "Info"ElseCall BersihCall AktifEnd IfEnd Sub

Private Sub CmdKeluar_Click()pesan = MsgBox("Yakin ingin keluar?", vbExclamation + vbYesNo, "Keluar")If pesan = vbYes ThenUnload MeEnd IfEnd Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)cepat = 100While Left + Width < Screen.WidthDoEventsLeft = Left + cepatWendWhile Top - Height < Screen.HeightDoEventsTop = Top + cepatWendHideUnload MeEnd Sub

 

 Form KK..

 Coding nya,,

Sub Aktif()Dim a As ControlFor Each a In Me    If TypeOf a Is TextBox Then a.Enabled = True    If TypeOf a Is ComboBox Then a.Enabled = True    NextEnd SubSub Nonaktif()Dim a As ControlFor Each a In Me    If TypeOf a Is TextBox Then a.Enabled = False    If TypeOf a Is ComboBox Then a.Enabled = False    NextEnd SubSub Bersih()Dim a As ControlFor Each a In Me    If TypeOf a Is TextBox Then a.Text = ""    If TypeOf a Is ComboBox Then a.Text = ""    NextEnd Sub

Private Sub CboKTP_Click()dbKTP.RecordSource = "select* from KTP where NIK='" & CboKTP.Text & "'"dbKTP.RefreshTxtNama.Text = dbKTP.Recordset!NamaTxtJekel.Text = dbKTP.Recordset!JekelTxtTempat.Text = dbKTP.Recordset!Tmp_Lahir

TxtTgl.Value = dbKTP.Recordset!Tgl_LahirTxtAlamat.Text = dbKTP.Recordset!AlamatTxtAgama.Text = dbKTP.Recordset!AgamaTxtPekerjaan.Text = dbKTP.Recordset!PekerjaanTxtStatus.Text = dbKTP.Recordset!Status'-----------------------------------------------------------'MsgBox "Data Penduduk Dengan NIK '" & CboKTP.Text & "' Sudah Ada", vbInformation, "Info" '<-- Pesan yang disisipkan'-----------------------------------------------------------                Exit SubEnd Sub

Private Sub CmdBatal_Click()BersihNonaktifEnd Sub

Private Sub CmdHapus_Click()Call BersihX = MsgBox("Yakin data ini akan di hapus?", vbOKCancel + vbExclamation, "Hapus")If X = vbOK ThendbKK.Recordset.DeleteMsgBox "Data sudah di hapus!", vbInformation, "Info"ElseCall BersihCall AktifEnd IfEnd Sub

Private Sub CmdKeluar_Click()pesan = MsgBox("Yakin ingin keluar?", vbExclamation + vbYesNo, "Keluar")If pesan = vbYes ThenUnload MeEnd IfEnd Sub

Private Sub CmdKoreksi_Click()

End Sub

Private Sub CmdSimpan_Click()dbKK.RecordSource = "select* from KK"dbKK.RefreshdbKK.Recordset.AddNewdbKK.Recordset!NKK = TxtNKKdbKK.Recordset!NIK = CboKTPdbKK.Recordset.UpdateMsgBox "Data Sudah Tersimpan!!!", vbInformation, "Konfirmas"Bersih

NonaktifEnd Sub

Private Sub CmdTambah_Click()tambah = TrueCall AktifCmdSimpan.Enabled = TrueCall BersihTxtNKK.SetFocusEnd Sub

Private Sub Form_Load()Me.dbKK.RefreshWith Me.dbKK.RecordsetIf .RecordCount > 0 Then.MoveFirstDo While Not .EOF.MoveNextLoopEnd IfEnd WithCombo_KTPBersihNonaktifEnd Sub

Sub Combo_KTP()dbKTP.RecordSource = "select NIK from ktp order by NIK"dbKTP.RefreshIf dbKTP.Recordset.RecordCount = 0 ThenExit SubElsedbKTP.Recordset.MoveFirstDo While Not dbKTP.Recordset.EOFCboKTP.AddItem dbKTP.Recordset!NIKdbKTP.Recordset.MoveNextLoopEnd IfEnd Sub

Private Sub TxtNKK_KeyPress(KeyAscii As Integer)If KeyAscii = 13 Then    dbKK.RecordSource = "select* from KK where NKK='" & TxtNKK.Text & "'"    dbKK.Refresh    dbKK.Recordset.Find "NKK='" & TxtNKK.Text & "'", , adSearchBackward, 1    If dbKK.Recordset.EOF Then        CboKTP.Text = ""        CboKTP.SetFocus        TxtNama.Text = ""        TxtJekel.Text = ""

        TxtTempat.Text = ""        TxtAlamat.Text = ""        TxtAgama.Text = ""        TxtPekerjaan.Text = ""        TxtStatus.Text = ""        CmdSimpan.Enabled = True    Else        CboKTP.Text = dbKK.Recordset!NIK        dbKTP.RecordSource = "select * from KTP" ' where NIK='" & CboKTP.Text & "'"        dbKTP.Refresh        dbKTP.Recordset.Find "Nik='" & CboKTP.Text & "'", , adSearchBackward, 1        If dbKTP.Recordset.EOF Then            CmdSimpan.Enabled = False            Exit Sub        Else            TxtNama.Text = dbKTP.Recordset!Nama            TxtJekel.Text = dbKTP.Recordset!Jekel            TxtTempat.Text = dbKTP.Recordset!Tmp_Lahir            TxtTgl.Value = dbKTP.Recordset!Tgl_Lahir            TxtAlamat.Text = dbKTP.Recordset!Alamat            TxtAgama.Text = dbKTP.Recordset!Agama            TxtPekerjaan.Text = dbKTP.Recordset!Pekerjaan            TxtStatus.Text = dbKTP.Recordset!Status        End If        CmdSimpan.Enabled = False    End IfEnd IfEnd Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)cepat = 100While Left + Width < Screen.WidthDoEventsLeft = Left + cepatWendWhile Top - Height < Screen.HeightDoEventsTop = Top + cepatWendHideUnload MeEnd Sub 

Transaksi

Coding transaksi

Sub Aktif()Dim a As ControlFor Each a In Me    If TypeOf a Is TextBox Then a.Enabled = True    If TypeOf a Is ComboBox Then a.Enabled = True    NextEnd SubSub Nonaktif()Dim a As ControlFor Each a In Me    If TypeOf a Is TextBox Then a.Enabled = False    If TypeOf a Is ComboBox Then a.Enabled = False    NextEnd SubSub Bersih()Dim a As ControlFor Each a In Me    If TypeOf a Is TextBox Then a.Text = ""    If TypeOf a Is ComboBox Then a.Text = ""    NextEnd SubPrivate Sub CboKK_Click()dbKK.RecordSource = "select* from KK where NKK='" & CboKK.Text & "'"dbKK.RefreshEnd Sub

Private Sub CboKTP_Click()dbKTP.RecordSource = "select* from KTP where NIK='" & CboKTP.Text & "'"dbKTP.Refresh

TxtNama.Text = dbKTP.Recordset!NamaTxtJekel.Text = dbKTP.Recordset!JekelTxtTempat.Text = dbKTP.Recordset!Tmp_LahirTxtTgl.Value = dbKTP.Recordset!Tgl_LahirTxtAlamat.Text = dbKTP.Recordset!AlamatTxtAgama.Text = dbKTP.Recordset!AgamaTxtPekerjaan.Text = dbKTP.Recordset!PekerjaanTxtStatus.Text = dbKTP.Recordset!StatusEnd Sub

Private Sub CmdBatal_Click()BersihNonaktifEnd Sub

Private Sub CmdHapus_Click()Call BersihX = MsgBox("Yakin data ini akan di hapus?", vbOKCancel + vbExclamation, "Hapus")If X = vbOK ThendbTransaksi.Recordset.DeleteMsgBox "Data sudah di hapus!", vbInformation, "Info"ElseCall BersihCall AktifEnd IfEnd Sub

Private Sub CmdKeluar_Click()pesan = MsgBox("Yakin ingin keluar?", vbExclamation + vbYesNo, "Keluar")If pesan = vbYes ThenUnload MeEnd IfEnd Sub

Private Sub CmdSimpan_Click()dbTransaksi.RecordSource = "select* from Transaksi"dbTransaksi.RefreshdbTransaksi.Recordset.AddNewdbTransaksi.Recordset!NKK = CboKKdbTransaksi.Recordset!NIK = CboKTPdbTransaksi.Recordset!SDK = TxtSDKdbTransaksi.Recordset!Nama1 = TxtNama1dbTransaksi.Recordset!Nama2 = TxtNama2dbTransaksi.Recordset!Kewarganegaraan = TxtKewarganegaraandbTransaksi.Recordset.UpdateMsgBox "Data Sudah Tersimpan!!!", vbInformation, "Konfirmas"BersihNonaktifEnd Sub

Private Sub CmdTambah_Click()BersihAktifEnd Sub

Private Sub Form_Load()Me.dbTransaksi.RefreshWith Me.dbTransaksi.RecordsetIf .RecordCount > 0 Then.MoveFirstDo While Not .EOF.MoveNextLoopEnd IfEnd WithCombo_KKCombo_KTPBersihNonaktifEnd SubSub Combo_KK()dbKK.RecordSource = "select NKK from KK order by NKK"dbKK.RefreshIf dbKK.Recordset.RecordCount = 0 ThenExit SubElsedbKK.Recordset.MoveFirstDo While Not dbKK.Recordset.EOFCboKK.AddItem dbKK.Recordset!NKKdbKK.Recordset.MoveNextLoopEnd IfEnd SubSub Combo_KTP()dbKTP.RecordSource = "select NIK from ktp order by NIK"dbKTP.RefreshIf dbKTP.Recordset.RecordCount = 0 ThenExit SubElsedbKTP.Recordset.MoveFirstDo While Not dbKTP.Recordset.EOFCboKTP.AddItem dbKTP.Recordset!NIKdbKTP.Recordset.MoveNextLoopEnd IfEnd Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)cepat = 100

While Left + Width < Screen.WidthDoEventsLeft = Left + cepatWendWhile Top - Height < Screen.HeightDoEventsTop = Top + cepatWendHideUnload MeEnd Sub

 

Seperti inilah menu utama nya bila di RUN,,,

Menu Utama

Coding menu utama

Dim i As LongDim merah, hijau, biru, yellow, magenta, hitam As IntegerPrivate Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long)

As LongPrivate Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As LongPrivate Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As LongDim Pos As Integer, StartPos As Integer, Lengh As Integer, iTeks As IntegerDim MyTeks As String

Private Sub DFGDG_Click()Shell "calc.exe", vbMaximizedFocusEnd Sub

Private Sub DFSDF_Click()pesan = MsgBox("Yakin ingin keluar?", vbExclamation + vbYesNo, "Keluar")If pesan = vbYes ThenUnload MeEnd IfEnd Sub

Private Sub DFSFD_Click()CrystalReport1.ReportFileName = App.Path & "\LaporanDataPenduduk.rpt"CrystalReport1.DataFiles(0) = App.Path & "\PENDUDUK.mdb"CrystalReport1.WindowState = crptMaximizedCrystalReport1.Action = 1End Sub

Private Sub FDSFFFS_Click()Trans.ShowEnd Sub

Private Sub FSFGF_Click()KK.ShowEnd Sub

Private Sub FSFS_Click()tt.ShowEnd Sub

Private Sub HTHYR_Click()CD1.ShowOpenmen.Picture = LoadPicture(CD1.FileName)End Sub

Private Sub Timer1_Timer()Static Count As IntegerIf (Label2.Left + Label2.Width) <= 0 Then        Label2.Left = Form1.Width        Count = Count + 1

        End If    Label2.Left = Label2.Left - 200End Sub

Private Sub Timer2_Timer()i = i + 1If i = 1000000 Then i = 0hijau = Int(255 * Rnd)biru = Int(255 * Rnd)yellow = Int(255 * Rnd)hitam = Int(255 * Rnd)Label2.ForeColor = RGB(biru, merah, hijau)End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)On Error Resume NextSelect Case Button.IndexCase 3tt.ShowCase 4KK.ShowCase 5Trans.ShowCase 7CrystalReport1.ReportFileName = App.Path & "\LaporanDataPenduduk.rpt"CrystalReport1.DataFiles(0) = App.Path & "\PENDUDUK.mdb"CrystalReport1.WindowState = crptMaximizedCrystalReport1.Action = 1Case 9pesan = MsgBox("Yakin ingin keluar?", vbExclamation + vbYesNo, "Keluar")If pesan = vbYes ThenUnload MeEnd IfEnd SelectEnd Sub

Rancang Laporan nya dengan menggunakan Cristal Report 8.5

Seperti ini lah bentuk laporan nya.. 

 

 

Ok Gan,,,

Slamat Mencoba ya..