MEMBUAT DATABASE DENGAN ADO Untuk membuat program ini, buatlah database dengan menggunakan Microsoft Access versi 2000 ke atas. Ketentuannya sebagai berikut : Nama Database Nama Table Field Primary Key : BRG : Supplier : KodeSupplier (Text/6),NamaSupplier (Text/50), Alamat (Text/100), Phone (Text/20), HP (Text/15), Email (Text/50), Contact (Text/50) : KodeSupplier Sebelum membuat form tambahkan komponen ADO Data Control dan Data Grid, lakukan langkah berikut : 1. Setelah membuat program (Standard EXE), muncul form 2. Klik menu Project, pilih Component, tandai dengan memberi tanda cek pada : a. Microsoft ADO Data Control 6.0 (OLDB) b. Microsoft Data Grid Control 6.0 (OLDB) 3. Akhiri dengan tekan tombol OK. Form Layout : Property Setting No Object Property Seting No Object Property Seting 1 Form Name frmsupplier 14 Text4 Name txtphone Caption Form Data Supplier Text 2 Label1 Caption Kode Supplier Font Arial [9] Font Arial [9] 15 Text5 Name txthp
3 Label2 Caption Nama Text Font Arial [9] Font Arial [9] 4 Label3 Caption Alamat 16 Text6 Name txtemail Font Arial [9] Text 5 Label4 Caption Phone Font Arial [9] Font Arial [9] 17 Text7 Name txtcp 6 Label5 Caption HP Text Font Arial [9] Font Arial [9] 7 Label6 Caption E-Mail 18 Command1 Name cmdnew Font Arial [9] Caption Baru 8 Label6 Caption Contact Person Font Arial [9] Font Arial [9] 19 Command2 Name cmdedit 9 Text1 Name txtkosup Caption Edit Font Arial [9] 20 Command3 Name cmddelete 10 Text2 Name txtnasup Caption Hapus Font Arial [9] 21 Command4 Name cmdend 11 Text3 Name txtalm Caption Keluar Font Arial [9] 12 Adodc1 Name AdoSup Caption ADO : Supplier ConnectionString Klik, klik Build, Pilih Microsoft Jet 4.0 OLDB, klik Next, klik. Pilih/cari file database (BRG), pilih Open, Klik OK, Klik OK Recordset Select * From Supplier 13 DataGrid1 Name DGS RecordSource AdoSup CODE : Private Sub Form_Activate() txtkosup.maxlength = 6 AdoSup.Refresh Private Sub Form_Load() 'menengahkan form ditengah-tengah layar frmsupplier.top = (Screen.Height - Height) / 2 frmsupplier.left = (Screen.Width - Width) / 2 'subrutin yang dijalankan pada saat tombol aktif diklik Private Sub cmdnew_click() 'jika tombol baru diklik, ubah menjadi tombol simpan If cmdnew.caption = "Baru" Then cmdnew.caption = "Simpan" cmdedit.enabled = False cmddelete.enabled = False 'tambahkan record kosong
AdoSup.Recordset.AddNew 'memanggil subrutin Aktif Aktif 'arahkan kursor pada textbox Kode txtkosup.setfocus Else 'ubah tombol Simpan menjadi tombol Baru cmdnew.caption = "Baru" 'memanggil subrutin cmdedit.enabled = True cmddelete.enabled = True 'subrutin bila tombol Hapus diklik Private Sub cmddelete_click() Dim x As String 'buat pertanyaan sebelum dihapus x = MsgBox("Benar " & txtnasup & "data ini mau dihapus?", vbyesno + vbcritical, "Hapus") 'jika tombol Yes dipilih If x = vbyes Then 'hapus record AdoSup.Recordset.Delete 'perbarui database AdoSup.Refresh AdoSup.Recordset.MoveFirst DGS.ReBind DGS.Refresh 'subrutin bila tombol Edit diklik Private Sub cmdedit_click() 'jika tombol Edit diklik, ubah menjadi tombol Update If cmdedit.caption = "Edit" Then cmdedit.caption = "Update" cmdnew.enabled = False cmddelete.enabled = False 'aktifkan form Aktif 'matikan textbox kode txtkosup.enabled = False 'arahkan kursor ke textbox nama barang txtnasup.setfocus Else 'ubah tombol update ke edit cmdedit.caption = "Edit" 'nonaktif kan form cmdnew.enabled = True cmddelete.enabled = True 'subrutin jika tombol keluar diklik Private Sub cmdend_click()
Unload Me 'tutup form 'subrutin yang membuat form tidak bisa diisi Sub () txtkosup.enabled = False txtnasup.enabled = False txtalm.enabled = False txtphone.enabled = False txthp.enabled = False txtemail.enabled = False txtcp.enabled = False 'subrutin yang membuat form bisa diisi Sub Aktif() txtkosup.enabled = True txtnasup.enabled = True txtalm.enabled = True txtphone.enabled = True txthp.enabled = True txtemail.enabled = True txtcp.enabled = True Private Sub txtkosup_keypress(keyascii As Integer) txtnasup.setfocus Private Sub txtnasup_keypress(keyascii As Integer) txtalm.setfocus Private Sub txtalm_keypress(keyascii As Integer) txtphone.setfocus Private Sub txtphone_keypress(keyascii As Integer) txthp.setfocus Private Sub txthp_keypress(keyascii As Integer) txtemail.setfocus Private Sub txtemail_keypress(keyascii As Integer)
txtcp.setfocus Private Sub txtcp_keypress(keyascii As Integer) If cmdnew.enabled = True Then cmdnew.setfocus Else cmdedit.setfocus