Anda di halaman 1dari 7

-----------------------------------------------------------------------------------

---------
CODING FORM DATA PENDUDUK
-----------------------------------------------------------------------------------
---------

Private Sub HAPUS_Click()


Application.ScreenUpdating = False
'Menentukan Object acuan data yang akan dihapus
If Me.NAMA.Value = "" Then
Call MsgBox("Pilih data pada tabel data", vbInformation, "Hapus Data")
Else
'Membuat pesan konfirmasi hapus data
Select Case MsgBox("Anda akan menghapus data" _
& vbCrLf & "Apakah anda yakin?" _
, vbYesNo Or vbQuestion Or vbDefaultButton1, "Hapus data")
Case vbNo
Exit Sub
Case vbYes
End Select
'Menentukan tempat hapus data, menghapus data dan membersihkan form
Set Hapusdata = Sheet2.Range("N7:N500000").Find(What:=Me.NIK.Value,
LookIn:=xlValues)
Hapusdata.Offset(0, -12).ClearContents
Hapusdata.Offset(0, -11).ClearContents
Hapusdata.Offset(0, -10).ClearContents
Hapusdata.Offset(0, -9).ClearContents
Hapusdata.Offset(0, -8).ClearContents
Hapusdata.Offset(0, -7).ClearContents
Hapusdata.Offset(0, -6).ClearContents
Hapusdata.Offset(0, -5).ClearContents
Hapusdata.Offset(0, -4).ClearContents
Hapusdata.Offset(0, -3).ClearContents
Hapusdata.Offset(0, -2).ClearContents
Hapusdata.Offset(0, -1).ClearContents
Hapusdata.Offset(0, 0).ClearContents
Hapusdata.Offset(0, 1).ClearContents
Hapusdata.Offset(0, 2).ClearContents
Call MsgBox("Data berhasil dihapus", vbInformation, "Hapus Data")
Me.NAMA.Value = ""
Me.KELAMIN.Value = ""
Me.PERNIKAHAN.Value = ""
Me.TEMPATLAHIR.Value = ""
Me.AGAMA.Value = ""
Me.PENDIDIKAN.Value = ""
Me.PEKERJAAN.Value = ""
Me.MEMBACA.Value = ""
Me.WARGANEGARA.Value = ""
Me.ALAMAT.Value = ""
Me.KEDUDUKAN.Value = ""
Me.NIK.Value = ""
Me.KK.Value = ""
Me.KETERANGAN.Value = ""
Call UrutPenduduk

End If
End Sub

Private Sub RESET_Click()


Me.NAMA.Value = ""
Me.KELAMIN.Value = ""
Me.PERNIKAHAN.Value = ""
Me.TEMPATLAHIR.Value = ""
Me.AGAMA.Value = ""
Me.PENDIDIKAN.Value = ""
Me.PEKERJAAN.Value = ""
Me.MEMBACA.Value = ""
Me.WARGANEGARA.Value = ""
Me.ALAMAT.Value = ""
Me.KEDUDUKAN.Value = ""
Me.NIK.Value = ""
Me.KK.Value = ""
Me.KETERANGAN.Value = ""
Me.TAMBAH.Enabled = True
End Sub

Private Sub TAMBAH_Click()


Application.ScreenUpdating = False
'Perintah untuk menentukan nama tempat simpan data
Dim DATAPENDUDUK As Object
'Perintah membuat tempat simpan data
Set DATAPENDUDUK = Sheet2.Range("B500000").End(xlUp)
'Perintah untuk menentukan Data inti / tambahan
If Me.NAMA.Value = "" _
Or Me.KELAMIN.Value = "" _
Or Me.PERNIKAHAN.Value = "" _
Or Me.TEMPATLAHIR.Value = "" _
Or Me.TANGGALLAHIR.Value = "" _
Or Me.WARGANEGARA.Value = "" _
Or Me.ALAMAT.Value = "" _
Or Me.KEDUDUKAN.Value = "" _
Or Me.NIK.Value = "" _
Or Me.KK.Value = "" Then
'Perintah memunculkan pesan jika data inti kosong
Call MsgBox("Maaf, Data input harus lengkap", vbInformation, "Input Data")
'Perintah untuk menyimpan data pada tempat simpan data
Else
DATAPENDUDUK.Offset(1, 0).Value = Me.NAMA.Value
DATAPENDUDUK.Offset(1, 1).Value = Me.KELAMIN.Value
DATAPENDUDUK.Offset(1, 2).Value = Me.PERNIKAHAN.Value
DATAPENDUDUK.Offset(1, 3).Value = Me.TEMPATLAHIR.Value
DATAPENDUDUK.Offset(1, 4).Value = Me.TANGGALLAHIR.Value
DATAPENDUDUK.Offset(1, 5).Value = Me.AGAMA.Value
DATAPENDUDUK.Offset(1, 6).Value = Me.PENDIDIKAN.Value
DATAPENDUDUK.Offset(1, 7).Value = Me.PEKERJAAN.Value
DATAPENDUDUK.Offset(1, 8).Value = Me.MEMBACA.Value
DATAPENDUDUK.Offset(1, 9).Value = Me.WARGANEGARA.Value
DATAPENDUDUK.Offset(1, 10).Value = Me.ALAMAT.Value
DATAPENDUDUK.Offset(1, 11).Value = Me.KEDUDUKAN.Value
DATAPENDUDUK.Offset(1, 12).Value = Me.NIK.Value
DATAPENDUDUK.Offset(1, 13).Value = Me.KK.Value
DATAPENDUDUK.Offset(1, 14).Value = Me.KETERANGAN.Value

On Error Resume Next


'Perintah untuk memasukkan data sheet ke dalam listbox
Sheet2.Select
Sheet1.TABELPENDUDUK.ListFillRange = "BUKUINDUK!A7:P" & Range("P" &
Rows.Count).End(xlUp).Row
Call MsgBox("Data berhasil ditambah", vbInformation, "Input Data")
Sheet1.Select
'Perintah untuk membersihkan form
Me.NAMA.Value = ""
Me.KELAMIN.Value = ""
Me.PERNIKAHAN.Value = ""
Me.TEMPATLAHIR.Value = ""
Me.AGAMA.Value = ""
Me.PENDIDIKAN.Value = ""
Me.PEKERJAAN.Value = ""
Me.MEMBACA.Value = ""
Me.WARGANEGARA.Value = ""
Me.ALAMAT.Value = ""
Me.KEDUDUKAN.Value = ""
Me.NIK.Value = ""
Me.KK.Value = ""
Me.KETERANGAN.Value = ""
End If
End Sub

Private Sub UBAH_Click()


Application.ScreenUpdating = False
Dim BARIS, SUMBERUBAH As String
If Me.NIK.Text = "" Then
Call MsgBox("Pilih data terlebih dahulu", vbInformation, "Pilih Data")
Else
Sheet2.Select
SUMBERUBAH = Sheets("BUKUINDUK").Cells(Rows.Count, "N").End(xlUp).Row
Sheets("BUKUINDUK").Range("N7:N" &
SUMBERUBAH).Find(What:=Sheet1.TABELPENDUDUK.Column(13), LookIn:=xlValues,
LookAt:=xlWhole).Activate
BARIS = ActiveCell.Offset(0, -12).Row

Cells(BARIS, 2) = Me.NAMA.Value
Cells(BARIS, 3) = Me.KELAMIN.Value
Cells(BARIS, 4) = Me.PERNIKAHAN.Value
Cells(BARIS, 5) = Me.TEMPATLAHIR.Value
Cells(BARIS, 6) = Me.TANGGALLAHIR.Value
Cells(BARIS, 7) = Me.AGAMA.Value
Cells(BARIS, 8) = Me.PENDIDIKAN.Value
Cells(BARIS, 9) = Me.PEKERJAAN.Value
Cells(BARIS, 10) = Me.MEMBACA.Value
Cells(BARIS, 11) = Me.WARGANEGARA.Value
Cells(BARIS, 12) = Me.ALAMAT.Value
Cells(BARIS, 13) = Me.KEDUDUKAN.Value
Cells(BARIS, 14) = Me.NIK.Value
Cells(BARIS, 15) = Me.KK.Value
Cells(BARIS, 16) = Me.KETERANGAN.Value

Call MsgBox("Data berhasil diubah", vbInformation, "Ubah Data")


Me.NAMA.Value = ""
Me.KELAMIN.Value = ""
Me.PERNIKAHAN.Value = ""
Me.TEMPATLAHIR.Value = ""
Me.AGAMA.Value = ""
Me.PENDIDIKAN.Value = ""
Me.PEKERJAAN.Value = ""
Me.MEMBACA.Value = ""
Me.WARGANEGARA.Value = ""
Me.ALAMAT.Value = ""
Me.KEDUDUKAN.Value = ""
Me.NIK.Value = ""
Me.KK.Value = ""
Me.KETERANGAN.Value = ""
End If
Unload Me
Sheet1.Select
End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()


With KELAMIN
.AddItem "Laki-Laki"
.AddItem "Perempuan"
End With
With PERNIKAHAN
.AddItem "Kawin"
.AddItem "Belum Kawin"
.AddItem "Janda"
.AddItem "Duda"
End With
With AGAMA
.AddItem "Islam"
.AddItem "Kristen"
.AddItem "Hindu"
.AddItem "Budha"
.AddItem "Konghucu"
.AddItem "Penghayat Kepercayaan"
End With
With PENDIDIKAN
.AddItem "SD"
.AddItem "SMP"
.AddItem "SMA/MA/SMU/Sederajat"
.AddItem "D1"
.AddItem "D2"
.AddItem "D3"
.AddItem "S1"
.AddItem "S2"
End With
With MEMBACA
.AddItem "L"
.AddItem "D"
.AddItem "A"
.AddItem "AL"
.AddItem "AD"
.AddItem "ALD"
End With
With WARGANEGARA
.AddItem "WNI"
.AddItem "WNA"
End With
With KEDUDUKAN
.AddItem "Kepala Keluarga"
.AddItem "Istri"
.AddItem "Anak Kandung"
.AddItem "Anak Tiri"
.AddItem "Pembantu"
End With
With PEKERJAAN
.AddItem "ASN"
.AddItem "Petani"
.AddItem "Buruh"
.AddItem "Wiraswasta"
End With

End Sub

----------------------------------------------------------------
CODING LISTBOX SHEET1
----------------------------------------------------------------
Private Sub TABELPENDUDUK_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Application.ScreenUpdating = False
On Error GoTo ERWIN
'Perintah memasukkan data dari ListBox ke TextBox

FORMBUKUINDUK.NAMA.Value = Sheet1.TABELPENDUDUK.Column(1)
FORMBUKUINDUK.KELAMIN.Value = Sheet1.TABELPENDUDUK.Column(2)
FORMBUKUINDUK.PERNIKAHAN.Value = Sheet1.TABELPENDUDUK.Column(3)
FORMBUKUINDUK.TEMPATLAHIR.Value = Sheet1.TABELPENDUDUK.Column(4)
FORMBUKUINDUK.TANGGALLAHIR.Value = Sheet1.TABELPENDUDUK.Column(5)
FORMBUKUINDUK.AGAMA.Value = Sheet1.TABELPENDUDUK.Column(6)
FORMBUKUINDUK.PENDIDIKAN.Value = Sheet1.TABELPENDUDUK.Column(7)
FORMBUKUINDUK.PEKERJAAN.Value = Sheet1.TABELPENDUDUK.Column(8)
FORMBUKUINDUK.MEMBACA.Value = Sheet1.TABELPENDUDUK.Column(9)
FORMBUKUINDUK.WARGANEGARA.Value = Sheet1.TABELPENDUDUK.Column(10)
FORMBUKUINDUK.ALAMAT.Value = Sheet1.TABELPENDUDUK.Column(11)
FORMBUKUINDUK.KEDUDUKAN.Value = Sheet1.TABELPENDUDUK.Column(12)
FORMBUKUINDUK.NIK.Value = Sheet1.TABELPENDUDUK.Column(13)
FORMBUKUINDUK.KK.Value = Sheet1.TABELPENDUDUK.Column(14)
FORMBUKUINDUK.KETERANGAN.Value = Sheet1.TABELPENDUDUK.Column(15)
FORMBUKUINDUK.TAMBAH.Enabled = False

Sheet2.Select
SUMBERUBAH = Sheets("BUKUINDUK").Cells(Rows.Count, "N").End(xlUp).Row
Sheets("BUKUINDUK").Range("N7:N" &
SUMBERUBAH).Find(What:=Sheet1.TABELPENDUDUK.Column(13), LookIn:=xlValues,
LookAt:=xlWhole).Activate
CELLAKTIF = ActiveCell.Offset(0, -12).Row
Sheets("BUKUINDUK").Range("B" & CELLAKTIF & ":P" & CELLAKTIF).Select
Sheet1.Select

FORMBUKUINDUK.Show
Exit Sub
ERWIN:
Call MsgBox("Maaf, klik 2x pada data yang ingin ditampilkan", vbInformation, "Data
Penduduk")

End Sub

-----------------------------------------------------------------------------------
-----------
CODING MODUL UTAMA
-----------------------------------------------------------------------------------
-----------
Sub BukaPenduduk()
FORMBUKUINDUK.Show
End Sub
Sub RefreshData()
On Error Resume Next
Application.ScreenUpdating = False
'Perintah untuk memasukkan data sheet ke dalam listbox
Sheet2.Select
Sheet1.TABELPENDUDUK.ListFillRange = "BUKUINDUK!A7:P" & Range("P" &
Rows.Count).End(xlUp).Row
Sheet1.Select
End Sub

Sub IsiDataDesa()
If Sheet1.Provinsi.Value = "" _
Or Sheet1.Kabupaten.Value = "" _
Or Sheet1.Kecamatan.Value = "" _
Or Sheet1.Desa.Value = "" _
Or Sheet1.Telpon.Value = "" _
Or Sheet1.Email.Value = "" Then
Call MsgBox("Isi data desa dengan lengkap", vbInformation, "Data Desa")
Else
Sheet1.Provinsi.Enabled = False
Sheet1.Kabupaten.Enabled = False
Sheet1.Kecamatan.Enabled = False
Sheet1.Desa.Enabled = False
Sheet1.Telpon.Enabled = False
Sheet1.Email.Enabled = False
Call MsgBox("Data desa telah diisi, silahkan Klik Reset untuk melakukan perubahan",
vbInformation, "Data Desa")
End If
End Sub

Sub ResetDesa()
Sheet1.Provinsi.Enabled = True
Sheet1.Kabupaten.Enabled = True
Sheet1.Kecamatan.Enabled = True
Sheet1.Desa.Enabled = True
Sheet1.Telpon.Enabled = True
Sheet1.Email.Enabled = True

End Sub

-----------------------------------------------------------------------------------
------------
CODING MODUL URUT
-----------------------------------------------------------------------------------
------------
Sub UrutPenduduk()
Application.ScreenUpdating = False
Sheet2.Select
Sheet2.Range("B6:P500000").Sort KEY1:=Range("B6"), Order1:=xlAscending,
Header:=xlYes
Sheet1.Select
End Sub