Punya Account Blogger?
Posted by Sofyan SOX on Sabtu, 26 Juni 2010 in











'koneksi database

Private Sub Form_Load()
  Me.Data1.DatabaseName = App.Path & "\type_a.mdb"
End Sub

'Membuat Prosedur

Sub kosong()
  Me.tkode = ""
  Me.tjenis = ""
  Me.tjudul = ""
  Me.tpengarang = ""
End Sub

Sub hidup()
  Me.tkode.Enabled = True
  Me.tjenis.Enabled = True
  Me.tjudul.Enabled = True
  Me.tpengarang.Enabled = True
End Sub

Sub mati()
  Me.tkode.Enabled = False
  Me.tjenis.Enabled = False
  Me.tjudul.Enabled = False
  Me.tpengarang.Enabled = False
End Sub

Sub tampil()
On Error Resume Next
 With Me.Data1.Recordset
   Me.tkode.Text = !kode
   Me.tjudul.Text = !judul
   Me.tjenis.Text = !jenis
   Me.tpengarang.Text = !pengarang
 End With
End Sub

Sub simpan()
 With Me.Data1.Recordset
   !kode = Me.tkode.Text
   !judul = Me.tjudul.Text
   !jenis = Me.tjenis.Text
   !pengarang = Me.tpengarang.Text
 End With
End Sub

Sub tombol(a, b, c, d As Boolean)
   Me.cadd.Enabled = a
   Me.csave.Enabled = b
   Me.ccancel.Enabled = c
   Me.cexit.Enabled = d
End Sub

Sub posisi()
   With Me.Data1.Recordset
     tpos.Text = .AbsolutePosition + 1
     tjml.Text = .RecordCount
   End With
End Sub

'Ketika Form Aktif

Private Sub Form_Activate()
  Call kosong
  Call mati
  Call posisi
  tombol 1, 0, 0, 1
  Me.cadd.SetFocus
End Sub

'Tombol Add si klik

Private Sub cadd_Click()
  Call kosong
  Call hidup
  tombol 0, 1, 1, 0
  Me.tkode.SetFocus
End Sub


'pencarian kode buku

Private Sub tkode_KeyPress(KeyAscii As Integer)
  If KeyAscii = 13 Then
  
    c = "kode='" + Me.tkode.Text + "'"
    Me.Data1.Recordset.FindFirst c
    
    If Me.Data1.Recordset.NoMatch Then
       Me.tjenis.SetFocus
    Else
       MsgBox "Kode Buku sudah ada", vbOKOnly + vbInformation, "Informasi"
       Call tampil
       Call mati
       tombol 1, 0, 0, 1
       Me.cadd.SetFocus
    End If
    
  End If
End Sub


'Menyimpan ke tabel

Private Sub csave_Click()
  Me.Data1.Recordset.AddNew
    Call simpan
  Me.Data1.Recordset.Update
    MsgBox "Data Tersimpan"
    Call kosong
    Call mati
    Call posisi
    tombol 1, 0, 0, 1
End Sub

'Membatalkan Penyimpanan

Private Sub ccancel_Click()
  Call kosong
  Call mati
  tombol 1, 0, 0, 1
  Me.cadd.SetFocus
End Sub

'Menutup Form

Private Sub cexit_Click()
  x = MsgBox("keluar ?", vbOKOnly + vbInformation, "Tutup Form")
  If x = vbYes Then Unload Me
End Sub


'Tombol Navigasi

Private Sub cfirst_Click()
  Me.Data1.Recordset.MoveFirst
  MsgBox "Posisi : Awal record", vbOKOnly + vbInformation, "Informasi"
  Call mati
  Call tampil
  Call posisi
End Sub

Private Sub clast_Click()
  Me.Data1.Recordset.MoveLast
  MsgBox "Posisi : Akhir record", vbOKOnly + vbInformation, "Informasi"
  Call mati
  Call tampil
  Call posisi
End Sub

Private Sub cprev_Click()
  With Me.Data1.Recordset
    If .BOF Then
        MsgBox "Posisi : Awal record", vbOKOnly + vbInformation, "Informasi"
        Call mati
        Call tampil
        Call posisi
    Else
        .MovePrevious
        If .BOF = False Then
           Call tampil
           Call posisi
        End If
    End If
  End With
End Sub

Private Sub cnext_Click()
  With Me.Data1.Recordset
    If .EOF Then
        MsgBox "Posisi : Akhir record", vbOKOnly + vbInformation, "Informasi"
        Call mati
        Call tampil
        Call posisi
    Else
        .MoveNext
        If .EOF = False Then
           Call tampil
           Call posisi
        End If
    End If
  End With
End Sub


vbuasA -

0 Responses to “Review Uas Kelas A”:

Posting Komentar