Tabel barang;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| kd_brg | char(6) | NO | PRI | | |
| nm_brg | char(30) | YES | | NULL | |
| satuan | char(10) | YES | | NULL | |
| harga | double | YES | | NULL | |
| stok | int(5) | YES | | NULL | |
| stok_min | int(4) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
create table barang(kd_brg char(6) primary key not null,nm_brg char(30),satuan char(10), harga double, stok int(5), stok_min int(4));
- Dari form kosong, pada properties form, pada caption isikan dengan “Pendataan Barang” sehingga akan tampak pada judul form.
- Pilih toolbox label, untuk membuat tulisan Kode Barang, Nama Barang, Satuan dan seterusnya.
- Pilih pada properties dan ganti masing-masing label sesuai dengan desain di atas.3. Pilih toolbox inputbox, untuk membuat inputan data mulai dari Kode Barang sampai dengan Stok Minimal. Kosongkan properties Text dari masing-masing inputbox.
- Pilih toolbox combobox, pada properties Text isikan “---Pilihan ---“, kemudian isikan satuan (Buah, Box, Lusin, Kg, Meter dll) pada properties List. Gunakan tombol CTRL + ENTER untuk pindah baris, jika selesai tekan ENTER.
- Pilih toolbox CommandButton, buat tombol sebanyak 10 dan sesuaikan dengan tampilan di atas. Semua text diisi pada properties Caption dari masing-masing commanbutton.
- Pilih toolbox DataGrid, isikan captionnya dengan “Informasi Data Barang”, apabila dataGrid belum ada maka tambahkan componennya dengan mengclick kanan pada area toolbox, pilih menu Components, pilih Microsoft ADO Data Control 6.0(OLEDB) dengan mencentak kotak kecil di sebelah kiri.
- Buat bingkai dengan Frame, properties caption diisi dengan “Pencarian Data”, buat label “Berdasarkan” dan “Teks yang dicari”, kemudian buat combobox dan textbox nya.
Tambahkan kode program berikut :
Dim rsbarang As New ADODB.Recordset
Dim strsql As String
Dim cek As Integer
Private Sub cmbsatuan_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then txtharga.SetFocus
End Sub
Private Sub cmdakhir_Click()
rsbarang.MoveLast 'pindah akhir record
End Sub
Private Sub cmdawal_Click()
rsbarang.MoveFirst 'pindah awal record
End Sub
Private Sub cmdbatal_Click()
tombol True
aktif False
End Sub
Private Sub cmdhapus_Click()
strsql = "delete from barang where kd_brg='" & _
txtkd_brg.Text & "'"
hapus = MsgBox("Yakin diHapus", vbYesNo, "Konfirmasi")
If hapus = vbYes Then
dbcon.Execute strsql
End If
rsbarang.Requery
End Sub
Private Sub cmdkeluar_Click()
dbcon.Close
Unload Me
End Sub
Private Sub cmdkoreksi_Click()
cek = 2
aktif True
tombol False
txtkd_brg.Enabled = False
txtnm_brg.SetFocus
End Sub
Private Sub cmdsebelum_Click()
On Error GoTo GoPrevError
If Not rsbarang.BOF Then rsbarang.MovePrevious
If rsbarang.BOF And rsbarang.RecordCount > 0 Then
Beep
'moved off the end so go back
rsbarang.MoveFirst
End If
'show the current record
Exit Sub
GoPrevError:
MsgBox Err.Description
End Sub
Private Sub cmdsesudah_Click()
On Error GoTo GoNextError
If Not rsbarang.EOF Then rsbarang.MoveNext
If rsbarang.EOF And rsbarang.RecordCount > 0 Then
Beep
'moved off the end so go back
rsbarang.MoveLast
End If
'show the current record
Exit Sub
GoNextError:
MsgBox Err.Description
End Sub
Private Sub cmdsimpan_Click()
On Error GoTo errSimpan
If cek = 1 Then
'tambah data
strsql = "insert into barang values('" & txtkd_brg.Text _
& "','" & txtnm_brg.Text & "','" & cmbsatuan.Text & "'," & _
Val(txtharga.Text) & "," & _
Val(txtstok.Text) & "," & Val(txtstok_min.Text) & ")"
Else
'edit data
strsql = "update barang set nm_brg='" & txtnm_brg.Text & _
"',satuan='" & cmbsatuan.Text & _
"',harga=" & Val(txtharga.Text) & _
",stok=" & Val(txtstok.Text) & _
",stok_min=" & Val(txtstok_min.Text) & _
" where kd_brg='" & txtkd_brg.Text & "'"
End If
' MsgBox strsql
dbcon.Execute (strsql) ' eksekusi perintah SQL
rsbarang.Requery
tombol True
aktif False
MsgBox "Sukses disimpan", vbOKOnly, "Konfirmasi Simpan"
Exit Sub
errSimpan:
MsgBox Err.Description, vbCritical, "Error Simpan"
End Sub
Private Sub cmdtambah_Click()
cek = 1
tombol False
aktif True
kosong
txtkd_brg.SetFocus
End Sub
Private Sub DgBarang_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
baca_data
End Sub
Private Sub Form_Activate()
tombol True
aktif False
baca_data
End Sub
Private Sub tombol(x)
cmdtambah.Enabled = x
cmdsimpan.Enabled = Not x
cmdkoreksi.Enabled = x
cmdhapus.Enabled = x
cmdbatal.Enabled = Not x
cmdkeluar.Enabled = x
cmdawal.Enabled = x
cmdakhir.Enabled = x
cmdsebelum.Enabled = x
cmdsesudah.Enabled = x
End Sub
Private Sub aktif(x)
txtkd_brg.Enabled = x
txtnm_brg.Enabled = x
cmbsatuan.Enabled = x
txtharga.Enabled = x
txtstok.Enabled = x
txtstok_min.Enabled = x
End Sub
Private Sub kosong()
txtkd_brg.Text = ""
txtnm_brg.Text = ""
cmbsatuan.Text = ""
txtharga.Text = ""
txtstok.Text = ""
txtstok_min.Text = ""
End Sub
Private Sub Form_Load()
nyambung
strsql = "select * from barang order by kd_brg asc"
rsbarang.Open strsql, dbcon
Set dgbarang.DataSource = rsbarang
rsbarang.Requery
load_cbocari "barang", cbocari
End Sub
Private Sub Form_Unload(Cancel As Integer)
tutup_koneksi
End Sub
Private Sub txtcari_Change()
strsql = "select * from barang where barang." & _
cbocari.Text & " LIKE ('%" & txtcari.Text & "%')"
rsbarang.Close
rsbarang.Open strsql, dbcon, adOpenStatic
rsbarang.Requery
dgbarang.Refresh
'lebar_grid
End Sub
Private Sub txtharga_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then txtstok.SetFocus
End Sub
Private Sub txtkd_brg_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then txtnm_brg.SetFocus
End Sub
Private Sub txtnm_brg_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then cmbsatuan.SetFocus
End Sub
Private Sub txtstok_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then txtstok_min.SetFocus
End Sub
Private Sub baca_data()
On Error Resume Next
If rsbarang.RecordCount > 0 Then 'untuk cek jumlah record
txtkd_brg.Text = rsbarang!kd_brg 'pindahkan data dr tabel ke form
txtnm_brg.Text = rsbarang!nm_brg
cmbsatuan.Text = rsbarang!satuan
txtharga.Text = rsbarang!harga
txtstok.Text = rsbarang!stok
txtstok_min.Text = rsbarang!stok_min
End If
End Sub
Jika menginginkan source code komplit silahkan email ke a71b_2008@yahoo.co.id.
sorry gan, mw tanya, itu databasenya bisa diperbaiki ga ?
ReplyDeletesaya bingung
maksud No dan Yes itu terdapat dibagian mana ya ?