Latihan Uas VB 1


' 1. Membersihkan Teks
Sub bersih()                         
txtno.Text = ""
Option1.Value = False
Option2.Value = False
cbkode.Text = "-pilih-"
txtlama.Text = ""
txtkembali.Text = ""
End Sub
' 2. Membuat No. Otomatis
Private Sub cmdadd_Click()
bersih
If adopinjam.Recordset.RecordCount > 0 Then
   adopinjam.Recordset.MoveLast
         txtno.Text = Val(adopinjam.Recordset!nopinjam) + 1
   Else
         txtno.Text = 1
   End If
End Sub
' 3. Menampilkan Jenis kode berdasarkan kode buku
Private Sub cbkode_Click()
     If cbkode.Text = "EK1" Then
         txtjenis.Text = "Ekonomi"
     ElseIf cbkode.Text = "AL1" Then
         txtjenis.Text = "Algoritma"
     Else
         txtjenis.Text = "Bahasa"
     End If
End Sub

'4. Menghitung Tanggal Kembali
Private Sub txtlama_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
       txtkembali.Text = DTPicker1.Value + Val(txtlama.Text)
    End If
End Sub
'5. Menyimpan Ke Tabel Pinjam
Private Sub cmdsave_Click()
    With adopinjam.Recordset
          .AddNew
               !nopinjam = txtno.Text
               !kdbuku = cbkode.Text
               !tglpinjam = DTPicker1.Value
               !tglkembali = txtkembali.Text

               If Option1.Value = True Then
                   !Status = Option1.Caption
               else
                   !Status = Option2.Caption
               End If

          .Update
       MsgBox "Data Tersimpan ", vbOKOnly, "Pemberitahuan"
   End With
End Sub
'6. Menghapus Record
Private Sub cmddel_Click()
     If MsgBox("Delete This Record ? ", vbOKCancel, "Confirm") = vbOK Then
         adopinjam.Recordset.Delete
     End If
End Sub
'7. Menutup Form
Private Sub cmdexit_Click()
     If MsgBox("Close This Form ? ", vbOKCancel, "Confirm") = vbOK Then
        Unload Me
     End If
End Sub
' 8. Tombol Navigasi
Private Sub cmdfirst_Click()
adopinjam.Recordset.MoveFirst
MsgBox "Awal Record!"
End Sub
Private Sub cmdlast_Click()
adopinjam.Recordset.MoveLast
MsgBox "Akhir Record!"
End Sub
Private Sub cmdnext_Click()

If adopinjam.Recordset.EOF = False Then
    adopinjam.Recordset.MoveNext
Else
    MsgBox "Awal Record!"
End If
End Sub
Private Sub cmdprev_Click()
If adopinjam.Recordset.BOF = False Then
     adopinjam.Recordset.MovePrevious
Else
    MsgBox "Awal Record!"

Share
»»  Baca lagi... Best Regard,
Image Hosted by ImageShack.us