VB (Listing Program VB 6.0)

Belajar Vb, belajar pemrograman, belajar coding, bahasa pemrograman, pemrograman dasar, belajar vb 6.0

Listing Program Visual Basic 6.0 Untuk Dua Form

Berikut ini saya post listing program VB 6.0 pada Form dengan satu Kunci Utama dan satu Kunci Tamu.

Gambar Form 1 Kunci Utama 1 Kunci Tamu


Dim vBaru As Boolean

Private Sub baru_Click()
If Baru.Caption = "Tambah" Then
Baru.Caption = "Batal"
hidup
Kosong

vBaru = True
MatiNav
Edit.Enabled = False
Hapus.Enabled = False

Else
Baru.Caption = "Tambah"
Text1 = ""
Kosong
mati
vBaru = True
MatiNav
Simpan.Enabled = False
Edit.Enabled = False
Hapus.Enabled = False
End If
End Sub

Private Sub edit_Click()
Hapus.Enabled = False
Baru.Enabled = True
Baru.Caption = "Batal"
MatiNav
Edit.Enabled = False
hidup
vBaru = False
End Sub

Private Sub form_load()
Text1.MaxLength = 15
With DE.rskedatangan
    If .State = 0 Then .Open
    .Filter = adFilterNone
End With
Simpan.Enabled = False
Edit.Enabled = False
Hapus.Enabled = False
End Sub

Private Sub hapus_Click()
If MsgBox("Hapus Data?", vbQuestion + vbYesNo, "") = vbYes Then
    DE.rskedatangan.Delete
    MsgBox "Data Terhapus"
    Text1 = ""
    Kosong
    vBaru = True
    MatiNav
End If
Baru.Caption = "Tambah"
Simpan.Enabled = False
Hapus.Enabled = False
Edit.Enabled = False
End Sub

Private Sub text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
DE.rskedatangan.Find "no_surat_datang='" + Text1.Text + "'", , adSearchForward, 1
If Not DE.rskedatangan.EOF Then
     MsgBox "Maaf, Nomor Surat Kedatangan dengan Nomor " + Text1.Text + " Sudah Ada!"
Else
Text2.SetFocus
End If
End If
End Sub

Private Sub simpan_Click()
With DE.rskedatangan
    If Text1.Text = "" Or Combo1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Or Text5.Text = "" Or Text6.Text = "" Or Text7.Text = "" Or Text8.Text = "" Or Text9.Text = "" Or Text10.Text = "" Or Text11.Text = "" Or Text12.Text = "" Or Text13.Text = "" Or Text14.Text = "" Or Text15.Text = "" Or Text16.Text = "" Or Text17.Text = "" Or Text18.Text = "" Or Text19.Text = "" Or Text20.Text = "" Or Combo2.Text = "" Or Text21.Text = "" Then
    MsgBox "Data Belum Lengkap"
        Exit Sub
    End If
    If .State = 0 Then .Open
    If vBaru = True Then .AddNew
    
    !nor_surat_datang = Text1.Text
    !NIK = Combo1.Text
    !nama_penduduk = Text2.Text
    !jenkel = Text3.Text
    !ttl = Text4.Text
    !warga_negara = Text5.Text
    !status_kawin = Text6.Text
    !agama = Text7.Text
    !pendidikan_terakhir = Text8.Text
    !hub_dlm_keluarga = Text9.Text
    !pekerjaan = Text10.Text
    !alamat = Text11.Text
    !datang_ke = Text12.Text
    !alamat_baru = Text13.Text
    !desa_kelurahan = Text14.Text
    !kecamatan = Text15.Text
    !kabupaten = Text16.Text
    !propinsi = Text17.Text
    !alasan_datang = Text18.Text
    !jumlah_ikut = Text19.Text
    !biaya = Text20.Text
    !id_petugas = Combo2.Text
    !nama_petugas = Text21.Text
    .Update
    MsgBox "Data Kedatangan Penduduk Telah Tersimpan"
    HidupNav
End With
Text1.Text = ""
Kosong
Baru.Caption = "Tambah"
mati
End Sub
Public Sub tengah()
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
End Sub

Public Sub Tampil()
With DE.rskedatangan
    If .State = 0 Then .Open
    Text1.Text = !no_surat_datang
    Combo1.Text = !NIK
    Text2.Text = !nama_penduduk
    Text3.Text = !jenkel
    Text4.Text = !ttl
    Text5.Text = !warga_negara
    Text6.Text = !status_kawin
    Text7.Text = !agama
    Text8.Text = !pendidikan_terakhir
    Text9.Text = !hub_dlm_keluarga
    Text10.Text = !pekerjaan
    Text11.Text = !alamat
    Text12.Text = !datang_ke
    Text13.Text = !alamat_baru
    Text14.Text = !desa_kelurahan
    Text15.Text = !kecamatan
    Text16.Text = !kabupaten
    Text17.Text = !propinsi
    Text18.Text = !alasan_datang
    Text19.Text = !jumlah_ikut
    Text20.Text = !biaya
    Combo2.Text = !id_petugas
    Text21.Text = !nama_petugas
End With
End Sub

Public Sub Kosong()
    Text1.Text = ""
    Combo1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
    Text5.Text = ""
    Text6.Text = ""
    Text7.Text = ""
    Text8.Text = ""
    Text9.Text = ""
    Text10.Text = ""
    Text11.Text = ""
    Text12.Text = ""
    Text13.Text = ""
    Text14.Text = ""
    Text15.Text = ""
    Text16.Text = ""
    Text17.Text = ""
    Text18.Text = ""
    Text19.Text = ""
    Text20.Text = ""
    Combo2.Text = ""
    Text21.Text = ""
End Sub

Public Sub MatiNav()
Simpan.Enabled = True
BukaKunci
End Sub

Public Sub HidupNav()
Baru.Enabled = True
Simpan.Enabled = False
kunci
End Sub

Public Sub kunci()
    Text1.Locked = True
    Combo1.Locked = True
    Text2.Locked = True
    Text3.Locked = True
    Text4.Locked = True
    Text5.Locked = True
    Text6.Locked = True
    Text7.Locked = True
    Text8.Locked = True
    Text9.Locked = True
    Text10.Locked = True
    Text11.Locked = True
    Text12.Locked = True
    Text13.Locked = True
    Text14.Locked = True
    Text15.Locked = True
    Text16.Locked = True
    Text17.Locked = True
    Text18.Locked = True
    Text19.Locked = True
    Text20.Locked = True
    Combo2.Locked = True
    Text21.Locked = True
End Sub

Public Sub BukaKunci()
    Text1.Locked = False
    Combo1.Locked = False
    Text2.Locked = False
    Text3.Locked = False
    Text4.Locked = False
    Text5.Locked = False
    Text6.Locked = False
    Text7.Locked = False
    Text8.Locked = False
    Text9.Locked = False
    Text10.Locked = False
    Text11.Locked = False
    Text12.Locked = False
    Text13.Locked = False
    Text14.Locked = False
    Text15.Locked = False
    Text16.Locked = False
    Text17.Locked = False
    Text18.Locked = False
    Text19.Locked = False
    Text20.Locked = False
    Combo2.Locked = False
    Text21.Locked = False
End Sub


Private Sub cari_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
DE.rskedatangan.Find "no_surat_datang='" + Cari.Text + "'", , adSearchForward, 1
If Not DE.rskedatangan.EOF Then
    Text1.Text = DE.rskedatangan!no_surat_datang
    Combo1.Text = DE.rskedatangan!NIK
    Text2.Text = DE.rskedatangan!nama_penduduk
    Text3.Text = DE.rskedatangan!jenkel
    Text4.Text = DE.rskedatangan!ttl
    Text5.Text = DE.rskedatangan!warga_negara
    Text6.Text = DE.rskedatangan!status_kawin
    Text7.Text = DE.rskedatangan!agama
    Text8.Text = DE.rskedatangan!pendidikan_terakhir
    Text9.Text = DE.rskedatangan!hub_dalam_keluarga
    Text10.Text = DE.rskedatangan!pekerjaan
    Text11.Text = DE.rskedatangan!alamat
    Text12.Text = DE.rskedatangan!datang_ke
    Text13.Text = DE.rskedatangan!alamat_baru
    Text14.Text = DE.rskedatangan!desa_kelurahan
    Text15.Text = DE.rskedatangan!kecamatan
    Text16.Text = DE.rskedatangan!kabupaten
    Text17.Text = DE.rskedatangan!propinsi
    Text18.Text = DE.rskedatangan!alasan_datang
    Text19.Text = DE.rskedatangan!jumlah_ikut
    Text20.Text = DE.rskedatangan!biaya
    Combo2.Text = DE.rskedatangan!id_petugas
    Text21.Text = DE.rskedatangan!nama_petugas
    mati
    Hapus.Enabled = True
    Edit.Enabled = True
Else
     MsgBox "Maaf, Data Kedatangan Penduduk Tidak Ditemukan!"
End If
End If
End Sub

Private Sub Combo1_click()
Call BukaDB
    rsPenduduk.Open "Select * from penduduk where NIK='" & Combo1 & "'", Conn
    If Not rsPenduduk.EOF Then
        Text2.Text = rsPenduduk!nama_penduduk
        Text3.Text = rsPenduduk!jenkel
        Text4.Text = rsPenduduk!ttl
        Text5.Text = rsPenduduk!warga_negara
        Text6.Text = rsPenduduk!status_kawin
        Text7.Text = rsPenduduk!agama
        Text8.Text = rsPenduduk!pendidikan_terakhir
        Text9.Text = rsPenduduk!hub_dlm_keluarga
        Text10.Text = rsPenduduk!pekerjaan
        Text11.Text = rsPenduduk!alamat
    Else
        MsgBox " NIK Penduduk Tidak Ditemukan"
        Combo1.SetFocus
    End If
End Sub

Private Sub Combo2_click()
Call BukaDB
    rsPetugas.Open "Select * from petugas where id_petugas='" & Combo2 & "'", Conn
    If Not rsPetugas.EOF Then
        Text21.Text = rsPetugas!nama_petugas
        
    Else
        MsgBox " ID Petugas Tidak Ditemukan"
        Combo2.SetFocus
    End If
End Sub

Public Sub mati()
    Text1.Enabled = False
    Combo1.Enabled = False
    Text2.Enabled = False
    Text3.Enabled = False
    Text4.Enabled = False
    Text5.Enabled = False
    Text6.Enabled = False
    Text7.Enabled = False
    Text8.Enabled = False
    Text9.Enabled = False
    Text10.Enabled = False
    Text11.Enabled = False
    Text12.Enabled = False
    Text13.Enabled = False
    Text14.Enabled = False
    Text15.Enabled = False
    Text16.Enabled = False
    Text17.Enabled = False
    Text18.Enabled = False
    Text19.Enabled = False
    Text20.Enabled = False
    Combo2.Enabled = False
    Text21.Enabled = False
End Sub

Public Sub hidup()
    Text1.Enabled = True
    Combo1.Enabled = True
    Text2.Enabled = True
    Text3.Enabled = True
    Text4.Enabled = True
    Text5.Enabled = True
    Text6.Enabled = True
    Text7.Enabled = True
    Text8.Enabled = True
    Text9.Enabled = True
    Text10.Enabled = True
    Text11.Enabled = True
    Text12.Enabled = True
    Text13.Enabled = True
    Text14.Enabled = True
    Text15.Enabled = True
    Text16.Enabled = True
    Text17.Enabled = True
    Text18.Enabled = True
    Text19.Enabled = True
    Text20.Enabled = True
    Combo2.Enabled = True
    Text21.Enabled = True
End Sub


Private Sub Form_Activate()
Call BukaDB
rsPenduduk.Open "SELECT * FROM penduduk ORDER BY 2", Conn
Combo1.Clear
Do Until rsPenduduk.EOF
    Combo1.AddItem rsPenduduk!NIK
    rsPenduduk.MoveNext
    Loop
Conn.Close

Call BukaDB
rsPetugas.Open "SELECT * FROM petugas ORDER BY 2", Conn
Combo2.Clear
Do Until rsPetugas.EOF
    Combo2.AddItem rsPetugas!id_petugas
    rsPetugas.MoveNext
    Loop
Conn.Close
End Sub


Silahkan baca juga Membuat Form Input Data


Subscribe to receive free email updates: