Tutorial, Source code, Request Program Visual Basic Oleh : Moh. A Azis Membuat Form Data Barang Program Persediaan Barang Form Data Barang digunakan untuk menyimpan data barang dan memberikan info mengenai stock barang yang disimpan. Untuk itu ikuti langkah-langkah di bawah ini 1. Perhatikan gambar di bawah ini, pada form baru anda tambahkan komponen Image, Label, box dan CommandButton 1
2. Lihat table di bawah ini, ubah properties komponen yang tertempel pada lembar form Nama Control Properties Nilai Form 1 Name FrmBarang Caption Data Barang Label 1 Caption Kode Barang : Label 2 Caption Nama Barang : Label 3 Caption Jumlah Barang : Label 4 Caption Satuan : Label 5 Caption Jenis Flute Box 1 Name Txtkd Box 2 Name Txtnm Box 3 Name Txtjumlah 2
Box 4 Name Txtsatuan Box 5 Name Txtjenis CommandButton1 Name Cmdcari Cari CommandButton1 Name Cmdsimpan Simpan CommandButton1 Name Cmdubah Ubah CommandButton1 Name Cmdhapus Hapus CommandButton1 Name Cmdbatal Batal CommandButton1 Name Cmdkeluar Keluar 3. Klik icon view code lalu copy pastekan listing kode di bawah ini : Option Explicit Dim panjang As Integer Dim hapus, kode As String Sub bersih() txtkd. = "" txtnm. = "" txtjumlah. = "" txtsatuan. = "" txtjenis. = "" cmdsimpan.enabled = True cmdubah.enabled = False cmdhapus.enabled = False 3
Private Sub cmdbatal_click() txtkd.setfocus Private Sub cmdcari_click() kode = InputBox("Masukkan kode barang", "Pencarian") If kode = "" Then Exit Sub On Error Resume Next sql = "select * from barang where kd_barang ='" & kode & "'" rs.open sql, db, adopendynamic, adlockbatchoptimistic If rs.eof = False Then txtkd. = rs.fields("kd_barang") txtnm. = rs.fields("nm_barang") txtjumlah. = rs.fields("jml_barang") txtsatuan. = rs.fields("satuan") txtjenis. = rs.fields("jns_flute") cmdsimpan.enabled = False cmdubah.enabled = True cmdhapus.enabled = True Else MsgBox "Data tidak ditemukan", vbinformation, "Message" End If Private Sub cmdhapus_click() 4
sql = "delete from barang where kd_barang = '" & txtkd. & "'" db.execute (sql) Private Sub cmdkeluar_click() Unload Me Private Sub cmdsimpan_click() If txtkd. = "" Then txtkd.setfocus: Exit Sub If txtnm. = "" Then txtnm.setfocus: Exit Sub If txtjumlah. = "" Then txtjumlah.setfocus: Exit Sub If txtsatuan. = "" Then txtsatuan.setfocus: Exit Sub If txtjenis. = "" Then txtjenis.setfocus: Exit Sub sql = "select * from barang where kd_barang ='" & txtkd. & "'" rs.open sql, db, adopendynamic, adlockbatchoptimistic If rs.eof = False Then MsgBox "Data Sudah Ada", vbinformation + vbokonly, "Pesan" : Exit Sub Else sql = "insert into barang values('" & txtkd. & "','" & txtnm. & "','" & _ Val(txtjumlah.) & "','" & txtsatuan. & "','" & txtjenis. & "')" db.execute (sql) 5
End If Private Sub cmdubah_click() If txtkd. = "" Then txtkd.setfocus: Exit Sub If txtnm. = "" Then txtnm.setfocus: Exit Sub If txtjumlah. = "" Then txtjumlah.setfocus: Exit Sub If txtsatuan. = "" Then txtsatuan.setfocus: Exit Sub If txtjenis. = "" Then txtjenis.setfocus: Exit Sub sql = "update barang set nm_barang ='" & txtnm. & "',jml_barang ='" & _ Val(txtjumlah.) & "',satuan='" & txtsatuan. & "',jns_flute ='" & _ txtjenis. & "' where kd_barang ='" & txtkd. & "'" db.execute (sql) Private Sub Form_Activate() txtkd.setfocus Private Sub Form_Load() Me.Top = 2500 Me.Left = 3750 6
Private Sub txtjumlah_keypress(keyascii As Integer) If KeyAscii = 13 Then txtsatuan.setfocus Private Sub txtsatuan_keypress(keyascii As Integer) If KeyAscii = 13 Then txtjenis.setfocus Private Sub txtnm_keypress(keyascii As Integer) If KeyAscii = 13 Then txtjumlah.setfocus Private Sub txtjenis_keypress(keyascii As Integer) If KeyAscii = 13 Then cmdsimpan.setfocus 4. Simpan Form Data Barang dengan nama FrmBarang di Folder Persediaan Barang dimana Project & Database Persediaan Barang dibuat 7