progam vb
Post on 07-Apr-2018
221 Views
Preview:
TRANSCRIPT
-
8/6/2019 Progam VB
1/5
MODUL VISUAL BASIC ADO MERCUSUAR
MEMBUAT DATABASE DENGAN ADO
Untuk membuat program ini, buatlah database dengan menggunakan Microsoft Access versi2000 ke atas. Ketentuannya sebagai berikut :
Nama Database : BRGNama Table : SupplierField : KodeSupplier (Text/6),NamaSupplier (Text/50),
Alamat (Text/100), Phone (Text/20), HP (Text/15),Email (Text/50), Contact (Text/50)
Primary Key : KodeSupplier
Sebelum membuat form tambahkan komponen ADO Data Control dan Data Grid, lakukanlangkah berikut :
1. Setelah membuat program (Standard EXE), muncul form2. 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
-
8/6/2019 Progam VB
2/5
MODUL VISUAL BASIC ADO MERCUSUAR
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 txtCP6 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
Text Font Arial [9]
Font Arial [9] 20 Command3 Name cmdDelete
10 Text2 Name txtNaSup Caption Hapus
Text Font Arial [9]
Font Arial [9] 21 Command4 Name cmdEnd
11 Text3 Name txtAlm Caption Keluar
Text Font Arial [9]
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
RecordsetSelect * FromSupplier
13 DataGrid1 Name DGS
RecordSource AdoSup
CODE :
Private Sub Form_Activate()
txtKoSup.MaxLength = 6
AdoSup.Refresh
NonAktif
End Sub
Private Sub Form_Load()
'menengahkan form ditengah-tengah layar
frmSupplier.Top = (Screen.Height - Height) / 2
frmSupplier.Left = (Screen.Width - Width) / 2End Sub
'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
-
8/6/2019 Progam VB
3/5
MODUL VISUAL BASIC ADO MERCUSUAR
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 NonAktif
NonAktif
cmdEdit.Enabled = True
cmdDelete.Enabled = True
End If
End Sub
'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
End If
End Sub
'subrutin bila tombol Edit diklikPrivate 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
NonAktif
cmdNew.Enabled = True
cmdDelete.Enabled = True
End If
End Sub
'subrutin jika tombol keluar diklik
Private Sub cmdEnd_Click()
-
8/6/2019 Progam VB
4/5
MODUL VISUAL BASIC ADO MERCUSUAR
Unload Me 'tutup form
End Sub
'subrutin yang membuat form tidak bisa diisi
Sub NonAktif()
txtKoSup.Enabled = False
txtNaSup.Enabled = FalsetxtAlm.Enabled = False
txtPhone.Enabled = False
txtHP.Enabled = False
txtEmail.Enabled = False
txtCP.Enabled = False
End Sub
'subrutin yang membuat form bisa diisi
Sub Aktif()
txtKoSup.Enabled = True
txtNaSup.Enabled = True
txtAlm.Enabled = True
txtPhone.Enabled = TruetxtHP.Enabled = True
txtEmail.Enabled = True
txtCP.Enabled = True
End Sub
Private Sub txtKoSup_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
txtNaSup.SetFocus
End If
End Sub
Private Sub txtNaSup_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 ThentxtAlm.SetFocus
End If
End Sub
Private Sub txtAlm_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
txtPhone.SetFocus
End If
End Sub
Private Sub txtPhone_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
txtHP.SetFocus
End If
End Sub
Private Sub txtHP_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
txtEmail.SetFocus
End If
End Sub
Private Sub txtEmail_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
-
8/6/2019 Progam VB
5/5
MODUL VISUAL BASIC ADO MERCUSUAR
txtCP.SetFocus
End If
End Sub
Private Sub txtCP_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If cmdNew.Enabled = True ThencmdNew.SetFocus
Else
cmdEdit.SetFocus
End If
End If
End Sub
top related