Tutorial, Source code, Request Program Visual Basic Oleh : Moh. A Azis Membuat Form Transaksi Barang Keluar Program Persediaan Barang Form barang keluar digunakan untuk melakukan transaksi penginputan barang keluar yang akan dikirim ke customer (pelanggan) dan menampilkan data barang yang akan keluar di tabel barang. Form transkasi barang keluar berikut menggunakan component vb listview untuk menampilkan data barang yang akan disimpan dan juga DTPicker untuk menampilkan tanggal, Untuk itu ikuti langkah-langkah di bawah ini 1
1. Untuk membuat component listview dan DTPicker buka dialog component dengan cara klik menu Project > Component. 2. Pada kotak dialog Components beri tanda centang pada pilihan Microsoft Windows Commont Control 6.0 (sp6) dan juga Microsoft Windows Commont Control-2 6.0 (SP4). Lihat gambar dibawah ini : 3. Perhatikan gambar di bawah ini, pada form baru anda tambahkan komponen seperti dibawah ini : 2
4. Lihat table di bawah ini, ubah properties komponen yang tertempel pada lembar form Nama Control Properties Nilai Form 1 Name FrmBarangKeluar Caption Barang Keluar DTPicker Name Dttgl Label 1 Caption Kode Customer : Label 2 Caption Nama Customer : Label 3 Caption Kode Barang : Label 4 Caption Nama Barang : Label 5 Caption Stock : Label 6 Caption Satuan : Label 7 Caption Jenis Flute : Label 8 Caption Jumlah 3
Label 9 Name lblnmcustomer Caption (dikosongkan) Label 10 Name Lblnm Caption (dikosongkan) Label 11 Name Lblstock Caption (dikosongkan) Label 12 Name Lblsatuan Caption (dikosongkan) Label 13 Name Lbljenis Caption (dikosongkan) Label 14 Name Lblitembrg Caption Item Barang : Label 15 Name Lblitemdata Caption Item Data : Label 16 Caption No. Barang Keluar : Label 17 Caption Tanggal : ComboBox1 Name Cmbkdcustomer TextBox 1 Name Txtkd TextBox 2 Name Txtno TextBox 3 Name Txtjml CommandButton1 Name cmddtbrg Text CommandButton2 Name Cmdsimpan Text Simpan CommandButton3 Name Cmdbatal Text Batal CommandButton4 Name Cmdkeluar Text Keluar 4
5. Klik icon view code lalu copy pastekan listing kode di bawah ini : Option Explicit Dim list As ListItem Dim Total As Single Dim jnsbarang As String Dim panjang As Integer Sub tabel_keluar() With ListView1.View = lvwreport.gridlines = True.FullRowSelect = True With.ColumnHeaders.Add,, "No", 498.Add,, "Kode Barang", 1666.Add,, "Nama Barang", 3800.Add,, "Satuan", 1440.Add,, "Jenis Flute", 1440.Add,, "Jumlah", 1000, 1 End With End With Sub no_barang_keluar() sql = "select * from Barang_Keluar" rs.open sql, db, adopendynamic, adlockbatchoptimistic With rs 5
txtno.text = "" If.EOF = False Then.MoveFirst Do While Not.EOF txtno.text =.Fields("no_keluar").MoveNext Loop panjang = Len(txtno.Text) - 4 txtno.text = "TBK-" & Val(Right(txtno.Text, panjang)) + 1 & "" Else txtno.text = "TBK-1" End If End With Sub bersih() Call no_barang_keluar lblitembrg.caption = "Item Barang :" lblitemdata.caption = "item data :0" ListView1.ListItems.Clear cmbkdcustomer.text = "" lblnmcustomer.caption = "" txtkd.text = "" lblnm.caption = "" lblstock.caption = "" lbljenis.caption = "" lblsatuan.caption = "" txtjml.text = "" dttgl.value = Format(Date, "dd/mm/yyyy") 6
Sub Transaksi() Set list = ListView1.ListItems.Add(,, "" & Mid(lblitemdata.Caption, 13, 25) & "") With list.subitems(1) = txtkd.text.subitems(2) = lblnm.caption.subitems(3) = lblsatuan.caption.subitems(4) = lbljenis.caption.subitems(5) = txtjml.text End With Sub kode_customer() sql = "select * from customer" rs.open sql, db, adopendynamic, adlockbatchoptimistic With rs cmbkdcustomer.clear If.EOF = False Then.MoveFirst Do While Not.EOF cmbkdcustomer.additem.fields("kd_customer").movenext Loop End If End With Private Sub cmbkdcustomer_click() 7
sql = "select * from customer where kd_customer = '" & cmbkdcustomer.text & "'" rs.open sql, db If rs.eof = False Then lblnmcustomer.caption = rs.fields("nm_customer") txtkd.setfocus End If Private Sub cmdbatal_click() sql = "delete from detail_barang_keluar where no_keluar = '" & _ txtno.text & "'" db.execute (sql) Call bersih txtkd.setfocus Private Sub cmddtbrg_click() FrmDataBarang.Show Private Sub cmdkeluar_click() Unload Me Private Sub cmdsimpan_click() If cmbkdcustomer.text = "" Then cmbkdcustomer.setfocus: Exit Sub sql = "insert into Barang_keluar values('" & txtno.text & "','" & _ 8
Format(dttgl, "yyyy/mm/dd") & "','" & cmbkdcustomer.text & "','" & _ FrmMenu_Utama.StatusBar1.Panels(1).Text & "')" db.execute (sql) MsgBox "Apakah Surat Jalan Ingin langsung di cetak???", vbinformation + vbyesno, "Pesan" If vbyes Then With CrystalReport1.ReportFileName = App.Path & "/Surat Jalan.rpt".SelectionFormula = "{Q_Surat_Jalan.no_keluar}='" & txtno.text & "'".RetrieveDataFiles.WindowState = crptmaximized.action = 1 End With Call bersih ListView1.ListItems.Clear cmbkdcustomer.setfocus Else Call bersih ListView1.ListItems.Clear cmbkdcustomer.setfocus End If Private Sub Form_Load() Call tabel_keluar Call bersih Call kode_customer 9
Private Sub TxtJml_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then If txtjml.text = "" Then txtjml.setfocus: Exit Sub If txtkd.text = "" Then txtkd.setfocus: Exit Sub If lblnm.caption = "" Then txtkd.setfocus: Exit Sub Dim a As Long a = Val(lblstock.Caption) - Val(txtjml.Text) lblitembrg.caption = "Item Barang : " & Val(Mid(lblitembrg.Caption, 14, 100)) _ + Val(txtjml.Text) & "" lblitemdata.caption = "Item Data : " & Val(Mid(lblitemdata.Caption, 13, 100)) _ + Val(1) & "" sql = "insert into detail_barang_keluar values('" & txtno.text & "','" & _ txtkd.text & "','" & Val(txtjml.Text) & "')" db.execute (sql) sql = "update barang set jml_barang ='" & a & "'where kd_barang ='" & txtkd.text & "'" db.execute (sql) Call Transaksi txtkd.text = "" lblnm.caption = "" lblstock.caption = "" lbljenis.caption = "" txtjml.text = "" lblsatuan.caption = "" txtkd.setfocus End If 10
Private Sub txtkd_change() If txtkd.text = "" Then GoTo proses On Error Resume Next sql = "select * from barang where kd_barang = '" & txtkd.text & "'" rs.open sql, db If rs.eof = False Then lblnm.caption = rs.fields("nm_barang") lblstock.caption = rs.fields("jml_barang") lbljenis.caption = rs.fields("jns_flute") lblsatuan.caption = rs.fields("satuan") txtjml.setfocus End If Exit Sub proses: txtkd.text = "" lblnm.caption = "" lblstock.caption = "" lbljenis.caption = "" txtjml.text = "" lblsatuan.caption = "" txtkd.setfocus Private Sub txtno_keypress(keyascii As Integer) KeyAscii = 0 11
Catatan : jika transaksi tersebut disimpan maka akan ototmatis keluar surat jalan barang yang akan dikirim ke customer (lihat kode yang saya tandai dengan warna merah). Untuk itu anda harus membuat surat jalan dengan crystal report 8.5 yang akan saya jelaskan pada tutorial selanjutnya 6. Simpan Form Barang Keluar dengan nama FrmBarangKeluar di Folder Persediaan Barang dimana Project & Database Persediaan Barang dibuat 12