Anda di halaman 1dari 3

Setelah lama tidak buka bahasa pemrograman Visual Basic, sekarang mau coba-coba lagi

biar ilmunya ga hilang…

Buatlah Form dengan lay out berikut ini :

Selanjutnya buatlah database dengan menggunakan software Microsoft Access 2003 :

Nama Database : Pustaka

Dalam Database pustaka buatlah tabel dengan nama : Buku

Kode_BukuJudul Pengarang Penerbit Tahun


Pemrograman Visual
Kom-1102 Basic Apri SiswantoUIR Press 2010
Ketik Pada Form Load Kode Berikut ini :

Private Sub Form_Load()

Set dbBUKU = New ADODB.Connection

dbBUKU.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\cONTOH vb\Data2


VB\APRI.VB\PUSTAKA.mdb;Persist Security Info=False”

tampil

End Sub

Private Sub tampil()


Set rsBUKU = New ADODB.Recordset

rsBUKU.CursorLocation = adUseClient

SQL = “select * from BUKU”

rsBUKU.Open SQL, dbBUKU, adOpenStatic, adLockReadOnly

Set DataGrid1.DataSource = rsBUKU

DataGrid1.Refresh

End Sub

Private Sub Text1_Change()

Dim rsBUKU As ADODB.Recordset

Set rsBUKU = New ADODB.Recordset

rsBUKU.CursorLocation = adUseClient

SQL = “select * from BUKU where Kode_Buku=’” & Text1 & “‘”

rsBUKU.Open SQL, dbBUKU, adOpenStatic, adLockReadOnly

If Not rsBUKU.EOF Then

Text2 = rsBUKU!Judul

Text3 = rsBUKU!Pengarang

Text4 = rsBUKU!Penerbit

Text5 = rsBUKU!Tahun

End If

End Sub

Private Sub Cmd_Simpan_Click()

If MsgBox(“yakin anda mau menyimpan data”, vbYesNo, “simpan Data”) = vbYes Then
dbBUKU.Execute (“insert into BUKU(Kode_Buku,Judul,Pengarang,Penerbit,Tahun) values
(‘” & Text1 & “‘,’” & Text2 & “‘,’” & Text3 & “‘,’” & Text4 & “‘,’” & Text5 & “‘)”)

tampil

End If
End Sub

Private Sub Cmd_Edit_Click()

If MsgBox(“yakin anda mau mengedit data”, vbYesNo, “simpan Data”) = vbYes Then

dbBUKU.Execute (“update BUKU set Judul=’” & Text2 & “‘,Pengarang=’” & Text3 &
“‘,Penerbit=’” & Text4 & “‘,Tahun=’” & Text5 & “‘where Kode_Buku= ‘” & Text1 & “‘”)

tampil

End If

End Sub

Private Sub Cmd_Delete_Click()

If MsgBox(“yakin anda mau menghapus data”, vbYesNo, “hapus Data”) = vbYes Then

dbBUKU.Execute (“delete from BUKU where Kode_Buku=’” & Text1 & “‘”)

tampil

End If

End Sub

Private Sub Cmd_Cancel_Click()

Text1.Text = “”

Text2.Text = “”

Text3.Text = “”

Text4.Text = “”

Text5.Text = “”

Text1.SetFocus

End Sub

Private Sub Cmd_Exit_Click()

End

End Sub

Selesai..

Anda mungkin juga menyukai