Membuat Form Barang
Pembahasan ini merupakan kelanjutan dari pokok bahasan "Membuat Aplikasi Inventory dan Lapoan Keuangan", baca terlebih dahulu pokok bahasan tersebut agar lebih jelas.
Pada pembahasan kali ini melanjutkan dari pembahasan Aplikasi Inventory dan Laporan Keuangan VB 6.0, kita lanjutkan untuk pembuatan Form Barang. Di blog-blog yang lain sudah banyak yang membahas mengenai pembuatan Data Barang, tetapi form data barang yang akan dibahas di sini adalah berdasarkan sebuah studi kasus di suatu tempat yang bergerak dibidang Dagang dan Anda nantinya dapat mengembangkan aplikasi ini untuk tempat yang lain.
Untuk membuat Form Master Data Barang di atas, kita tambahkan terlebih dahulu File Form ke dalam project kita melalui menu Project ⇛ Add Form. Maka akan muncul kotak dialog seperti gambar berikut.
Anda pilih Form, kemudian Anda klik open.
Silahkan Anda simpan kembali Project Anda, Simpan form yang barusaja Anda tambahkan ke dalam project dengan nama Frm_MasBar.frm. Kemudian Anda desain form tersebut seperti gambar di bawah ini.
GAMBAR 1
GAMBAR 2
Dalam tampilan desain Form Master Data Barang terdapat dua tampilan seperti GAMBAR 1 dan GAMBAR 2. Pada tampilan GAMBAR 1 adalah tampilan untuk Input Data, Edit Data, Hapus Data, dan Cetak Data. Sedangkan pada GAMBAR 2 adalah tampilan untuk Pengurutan Data dan Pencarian Data.
Pengaturan Objek GAMBAR 1 dan GAMBAR 2
Kontrol
Properties
Nilai
Form1
Name
Caption
Font
Font size
Font style
Picture
Frm_login
SIA – MASTER BARANG
Arial
10
Standard
[ambil dari komputer gambar yang sudah
Anda download]
Frame
Name
Caption
Frame1
DATA BARANG
SSTab
Name
Tabs
TabPerRow
SSTab1
2
2
Pengaturan Custom pada objek SSTab
seperti gambar di bawah ini.
Label1
Name
Caption
Font
Font size
Font style
Label1
Kode Barang
Arial
10
Standard
Label2
Name
Caption
Font
Font Size
Font Style
Label2
Nama Barang
Arial
10
Standard
Label3
Name
Caption
Font
Font Size
Font Style
Label3
Ukuran
Arial
10
Standard
Label4
Name
Caption
Font
Font Size
Font Style
Label4
Satuan
Arial
10
Standard
Label5
Name
Caption
Font
Font Size
Font Style
Label5
Harga Jual
Arial
10
Standard
Label6
Name
Caption
Font
Font Size
Font Style
Label6
Stock Awal
Arial
10
Standard
Label7
Name
Caption
Font
Font Size
Font Style
Label7
Stock Minimal
Arial
10
Standard
Label8
Name
Caption
Font
Font Size
Font Style
Label8
Stock Max
Arial
10
Standard
TextBox1
Name
Font
Font Size
Font Style
Text
T_Kode
Arial
10
Standard
[dikosongkan]
TextBox2
Name
Font
Font Size
Font Style
Text
T_Nama
Arial
10
Standard
[dikosongkan]
TextBox3
Name
Font
Font Size
Font Style
Text
T_Ukuran
Arial
10
Standard
[dikosongkan]
ComboBox
Name
Font
Font Size
Font Style
Text
List
Cbo_Satuan
Arial
10
Standard
PCS
PCS
BOX
UNIT
GR
KG
MaskEditBox
Name
DataFormat
Font
Font Size
Font Style
Format
PromptChar
T_HrgJual
Currency
Arial
10
Standard
Rp #,##0
_
TextBox4
Name
Font
Font Size
Font Style
Text
T_StockAwal
Arial
10
Standard
[dikosongkan]
TextBox5
Name
Font
Font Size
Font Style
Text
T_StockMin
Arial
10
Standard
[dikosongkan]
TextBox6
Name
Font
Font Size
Font Style
Text
T_StockMax
Arial
10
Standard
[dikosongkan]
DataGrid
Name
Font
Font Size
Font Style
DG_Input
Arial
10
Standard
Adodc
Name
ConnectionString
ADOBRG
Provider=MSDASQL.1;Persist Security
Info=False;User ID=root;Data Source=DBSIARETAIL;Initial Catalog=dbsiaretail
CommandButton1
Name
Caption
Font
Font Size
Font Style
Cmd_Cari
&Cari
Verdana
10
Standard
CommandButton2
Name
Caption
Font
Font Size
Font Style
Cmd_Tambah
&Tambah
Verdana
10
Standard
CommandButton3
Name
Caption
Font
Font Size
Font Style
Cmd_Batal
&Batal
Verdana
10
Standard
CommandButton4
Name
Caption
Font
Font Size
Font Style
Cmd_Cetak
Ceta&k
Verdana
10
Standard
CommandButton5
Name
Caption
Font
Font Size
Font Style
Cmd_Simpan
&Simpan
Verdana
10
Standard
CommandButton6
Name
Caption
Font
Font Size
Font Style
Cmd_Edit
&Edit
Verdana
10
Standard
CommandButton7
Name
Caption
Font
Font Size
Font Style
Cmd_Hapus
&Hapus
Verdana
10
Standard
CommandButton8
Name
Caption
Font
Font Size
Font Style
Cmd_Tutup
TUTUP
Verdana
10
Standard
Isi dari SSTab(1) TABEL DATA BARANG.
Label9
Name
Caption
Font
Font size
Font style
Label9
Urutan
Arial
10
Standard
Label10
Name
Caption
Font
Font Size
Font Style
Label10
Cari Berdasarkan
Arial
10
Standard
Label11
Name
Caption
Font
Font Size
Font Style
Label11
Cari Data
Arial
10
Standard
ComboBox
Name
Font
Font Size
Font Style
Text
List
Cbo_Urut
Arial
10
Standard
Kode Barang
Kode
Barang
Nama
Ukuran
Satuan
Harga
Jual
ComboBox
Name
Font
Font Size
Font Style
Text
List
Cbo_Cari
Arial
10
Standard
Kode Barang
Kode
Barang
Nama
Ukuran
Satuan
Harga
Jual
TextBox7
Name
Font
Font Size
Font Style
Text
T_Cari
Arial
10
Standard
[dikosongkan]
DataGrid
Name
Font
Font Size
Font Style
DG_Data
Arial
10
Standard
Selanjutnya Tuliskan Kode Programnya seperti berikut.
KODE PROGRAM Module Login
'Deklarasi koneksi dan recordset
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub cmd_tutup_Click()
Unload Me
End Sub
Private Sub Form_Activate()
'Ukuran dan posisi form
Me.Top = 100
Me.Left = 1000
ADO_BRG.Refresh
End Sub
Private Sub Form_Load()
Call JumlahData
End Sub
Private Sub Cmd_Batal_Click()
T_Kode.Enabled = True
T_Nama.Enabled = True
T_Ukuran.Enabled = True
T_stockawal.Enabled = True
T_HrgJual.Enabled = True
T_StockMax.Enabled = True
T_StockMin.Enabled = True
Cbo_Satuan.Enabled = True
Call Kosong
Cmd_Edit.Enabled = False
Cmd_Hapus.Enabled = False
Cmd_Batal.Enabled = False
Cmd_Tambah.Enabled = True
End Sub
Private Sub Cmd_Hapus_click()
Dim sql As String
Dim konfirmasi As String
On Error GoTo SalahHapus
If T_Kode.Text <> "" And T_Kode.Enabled = False Then
konfirmasi = MsgBox("Mau Hapus Record???", vbYesNo + vbCritical, "Konfirmasi")
If konfirmasi = vbYes Then
'Menghapus record pada tabel
sql = "Delete From Barang " & _
" Where kd_Barang='" & T_Kode.Text & "'"
'Mengeksekusi perintah SQL
Conn.Execute (sql)
T_Kode.Enabled = True
T_Nama.Enabled = True
Cbo_Satuan.Enabled = True
T_HrgJual.Enabled = True
T_stockawal.Enabled = True
T_StockMin.Enabled = True
T_StockMax.Enabled = True
T_Ukuran.Enabled = True
Cmd_Tambah.Enabled = True
Cmd_Simpan.Enabled = False
Cmd_Hapus.Enabled = False
Cmd_Edit.Enabled = True
Cmd_Batal.Enabled = True
Call Kosong
Call sambung
Call JumlahData
End If
End If
ADO_BRG.Refresh
Exit Sub
SalahHapus:
Select Case Err.Number
Case -2147217900
errmsg = " Data Masih Terhubung Oleh Tabel Lain " & vbCrLf
Case Else
errmsg = Err.Description
End Select
MsgBox errmsg, vbCritical + vbOKOnly, "Informasi:"
End Sub
Private Sub cmd_Keluar_Click()
'Keluar dari form
Unload Me
End Sub
Private Sub cmd_Simpan_Click()
Dim sql As String
Dim panjang As Byte
panjang = Len(T_Kode.Text)
On Error GoTo SalahIsi
If T_Kode.Text = "" Or T_Nama.Text = "" Or T_Ukuran = "" Or Cbo_Satuan = "" Or T_HrgJual = "" Or T_stockawal = "" Or T_StockMax = "" Or T_StockMin = "" Then
MsgBox "Data Belum Lengkap", vbOKOnly, "Data"
ElseIf panjang < 5 Then
MsgBox "Kode Barang Minimal 5 Digit", vbCritical + vbOKOnly, "Kode Barang"
ElseIf Val(T_StockMax.Text) < Val(T_StockMin.Text) _
Then MsgBox " Jumlah Stock Max Sama " + Chr(13) + "atau lebih dari Stock Min"
T_StockMax.SetFocus
T_StockMax.Text = ""
ElseIf T_Kode.Text <> "" And T_Nama.Text <> "" And T_Ukuran.Text <> "" And Cbo_Satuan.Text <> "" And T_HrgJual.Text <> "" And T_stockawal <> "" And T_StockMax.Text <> "" And T_StockMin.Text <> "" _
And Val(T_StockMax.Text) >= Val(T_StockMin.Text) And panjang >= 5 Then
If T_Kode.Enabled = True Then
'Menambah record pada tabel
sql = "Insert into Barang Values('" & T_Kode.Text & "','" & T_Nama.Text & "','" & T_Ukuran.Text & "','" & Cbo_Satuan.Text & " '," & Val(T_HrgJual.Text) & "," & Val(T_stockawal.Text) & "," & Val(T_StockMin.Text) & "," & Val(T_StockMax.Text) & ") "
'Mengeksekusi perintah SQL
Conn.Execute (sql)
Call sambung
ADO_BRG.Refresh
Call sambung
Call JumlahData
Else
'Mengubah record pada tabel
sql = "Update Barang set " & _
" NamaBarang='" & T_Nama.Text & "'," & _
" Ukuran='" & T_Ukuran.Text & "'," & _
" satuan='" & Cbo_Satuan.Text & "'," & _
" HargaJualBarang=" & T_HrgJual.Text & "," & _
" stockAwal=" & T_stockawal.Text & "," & _
" stockmin=" & T_StockMin.Text & "," & _
" stockmax=" & T_StockMax.Text & " Where Kd_Barang='" & T_Kode.Text & "'"
'Mengeksekusi perintah SQL
Conn.Execute (sql)
End If
T_Kode.Enabled = False
T_Nama.Enabled = False
Cbo_Satuan.Enabled = False
T_HrgJual.Enabled = False
T_stockawal.Enabled = False
T_StockMin.Enabled = False
T_StockMax.Enabled = False
T_Ukuran.Enabled = False
Cmd_Simpan.Enabled = False
Cmd_Batal.Enabled = False
Cmd_Tambah.Enabled = True
Cmd_Hapus.Enabled = True
Cmd_Edit.Enabled = True
End If
ADO_BRG.Refresh
ADO_BRG.Recordset.MoveLast
Exit Sub
SalahIsi:
Select Case Err.Number
Case -2147217833
errmsg = " Angka Yang Anda Masukaan Terlalu Banyak " & vbCrLf
Case Else
errmsg = Err.Description
End Select
MsgBox errmsg, vbCritical + vbOKOnly, "Informasi:"
'MsgBox "Error:" & Err & "" & Err.Description
End Sub
Private Sub cmd_Tambah_Click()
T_Kode.Enabled = True
T_Nama.Enabled = True
Cbo_Satuan.Enabled = True
T_HrgJual.Enabled = True
T_stockawal.Enabled = True
T_StockMin.Enabled = True
T_StockMax.Enabled = True
T_Ukuran.Enabled = True
Cmd_Tambah.Enabled = False
Cmd_Simpan.Enabled = True
Cmd_Edit.Enabled = False
Cmd_Hapus.Enabled = False
Cmd_Batal.Enabled = True
Call Kosong
T_Kode.SetFocus
End Sub
Private Sub cmd_edit_Click()
Dim sql As String
If T_Kode.Text <> "" And T_Kode.Enabled = False Then
T_Nama.Enabled = True
Cbo_Satuan.Enabled = True
T_HrgJual.Enabled = True
T_stockawal.Enabled = True
T_StockMin.Enabled = True
T_StockMax.Enabled = True
T_Ukuran.Enabled = True
End If
Cmd_Edit.Enabled = False
Cmd_Hapus.Enabled = False
Cmd_Simpan.Enabled = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Menutup koneksi
Set Conn = Nothing
End Sub
Private Sub T_hrgjual_keypress(keyascii As Integer)
If Not (keyascii >= Asc("0") & Chr(13) _
And keyascii <= Asc("9") & Chr(13) _
Or keyascii = vbKeyBack _
Or keyascii = vbKeyDelete) And Not (keyascii = 13) Then
Beep
keyascii = 0
MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan"
ElseIf keyascii = 46 Then
keyascii = 0
MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan"
ElseIf keyascii = 13 Then
SendKeys vbTab
End If
End Sub
Private Sub t_Kode_KeyPress(keyascii As Integer)
Dim sTemplate As String
'Ganti '!@#$%^&*()_+=' dengan karakter yang Anda
'inginkan untuk dihindari diinput pada Text1
sTemplate = "`~@#$%^&*()_+|=\<,>?/;:'"""
If InStr(1, sTemplate, Chr(keyascii)) > 0 Then _
keyascii = 0
'Pembacaan tombol Enter
If keyascii = 13 Then
'Menjalankan fungsi TAB
SendKeys vbTab
Else
'Membuat huruf besar
keyascii = Asc(UCase(Chr(keyascii)))
End If
End Sub
Private Sub t_Kode_LostFocus()
Dim sql As String
Call sambung
If T_Kode.Text <> "" Then
'Mencari Kode pada tabel
sql = "select * from Barang " & _
" where kd_Barang='" & T_Kode.Text & "'"
Set rs = Conn.Execute(sql)
'Jika Kode sudah ada
If Not rs.EOF Then
'Menampilkan field yang lain
T_Nama.Text = rs.Fields("NamaBarang")
T_Ukuran.Text = rs.Fields("ukuran")
Cbo_Satuan.Text = rs.Fields("satuan")
T_HrgJual.Text = rs.Fields("HargaJualBarang")
T_stockawal.Text = rs.Fields("stockawal")
T_StockMin.Text = rs.Fields("stockmin")
T_StockMax.Text = rs.Fields("stockmax")
T_Kode.Enabled = False
T_Nama.Enabled = False
T_Ukuran.Enabled = False
Cbo_Satuan.Enabled = False
T_HrgJual.Enabled = False
T_stockawal.Enabled = False
T_StockMin.Enabled = False
T_StockMax.Enabled = False
Cmd_Tambah.Enabled = True
Cmd_Hapus.Enabled = True
Cmd_Edit.Enabled = True
Else
Cmd_Simpan.Enabled = True
Cmd_Batal.Enabled = True
End If
rs.Close
End If
End Sub
Private Sub Cmd_Cari_click()
Dim sql As String
Call sambung
If T_Kode.Text = "" Then
MsgBox "Masukkan Data yang Akan Dicari"
T_Kode.SetFocus
ElseIf T_Kode.Text <> "" Then
'Mencari Kode pada tabel
sql = "select * from Barang " & _
" where kd_Barang='" & T_Kode.Text & "'"
Set rs = Conn.Execute(sql)
'Jika Kode sudah ada
If Not rs.EOF Then
'Menampilkan field yang lain
T_Nama.Text = rs.Fields("NamaBarang")
T_Ukuran.Text = rs.Fields("ukuran")
Cbo_Satuan.Text = rs.Fields("satuan")
T_HrgJual.Text = rs.Fields("HargaJualBarang")
T_stockawal.Text = rs.Fields("stockawal")
T_StockMin.Text = rs.Fields("stockmin")
T_StockMax.Text = rs.Fields("stockmax")
T_Kode.Enabled = False
T_Nama.Enabled = False
T_Ukuran.Enabled = False
Cbo_Satuan.Enabled = False
T_HrgJual.Enabled = False
T_stockawal.Enabled = False
T_StockMin.Enabled = False
T_StockMax.Enabled = False
Cmd_Tambah.Enabled = True
Cmd_Hapus.Enabled = True
Cmd_Edit.Enabled = True
Else
Cmd_Simpan.Enabled = True
Cmd_Batal.Enabled = True
End If
If rs.EOF Then
MsgBox "Data yang Anda Cari Tidak Ada", vbInformation, "Data Tidak Ada"
T_Kode.Text = ""
T_Kode.SetFocus
rs.Close
End If
End If
End Sub
Private Sub t_Nama_KeyPress(keyascii As Integer)
Dim sTemplate As String
'Ganti '!@#$%^&*()_+=' dengan karakter yang Anda
'inginkan untuk dihindari diinput pada Text1
sTemplate = "`~@#$%^&*()+|=\<,>?/;:'"""
If InStr(1, sTemplate, Chr(keyascii)) > 0 Then _
keyascii = 0
'Pembacaan tombol Enter
If keyascii = 13 Then
'Menjalankan fungsi TAB
SendKeys vbTab
Else
'Membuat huruf besar
keyascii = Asc(UCase(Chr(keyascii)))
End If
End Sub
Private Sub t_ukuran_KeyPress(keyascii As Integer)
Dim sTemplate As String
'Ganti '!@#$%^&*()_+=' dengan karakter yang Anda
'inginkan untuk dihindari diinput pada Text1
sTemplate = "`~@#$^&*()_+|=\<,>?/;:'"""
If InStr(1, sTemplate, Chr(keyascii)) > 0 Then _
keyascii = 0
'Pembacaan tombol Enter
If keyascii = 13 Then
'Menjalankan fungsi TAB
SendKeys vbTab
Else
'Membuat huruf besar
keyascii = Asc(UCase(Chr(keyascii)))
End If
End Sub
Private Sub T_stockawal_keypress(keyascii As Integer)
''If Not (keyascii >= Asc("0") & Chr(13) _
'' And keyascii <= Asc("9") & Chr(13) _
'' Or keyascii = vbKeyBack _
'' Or keyascii = vbKeyDelete) And Not (keyascii = 13) Then
'' Beep
'' keyascii = 0
'' MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan"
'' ElseIf keyascii = 46 Then
'' keyascii = 0
'' MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan"
''Else
If keyascii = 13 Then
SendKeys vbTab
End If
End Sub
Private Sub T_stockmin_keypress(keyascii As Integer)
''If Not (keyascii >= Asc("0") & Chr(13) _
'' And keyascii <= Asc("9") & Chr(13) _
'' Or keyascii = vbKeyBack _
'' Or keyascii = vbKeyDelete) And Not (keyascii = 13) Then
'' Beep
'' keyascii = 0
'' MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan"
'' ElseIf keyascii = 46 Then
'' keyascii = 0
'' MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan"
''Else
If keyascii = 13 Then
SendKeys vbTab
End If
End Sub
Private Sub T_stockmax_keypress(keyascii As Integer)
''If Not (keyascii >= Asc("0") & Chr(13) _
'' And keyascii <= Asc("9") & Chr(13) _
'' Or keyascii = vbKeyBack _
'' Or keyascii = vbKeyDelete) And Not (keyascii = 13) Then
'' Beep
'' keyascii = 0
'' MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan"
'' ElseIf keyascii = 46 Then
'' keyascii = 0
'' MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan"
''Else
If keyascii = 13 Then
SendKeys vbTab
End If
End Sub
Sub Kosong()
'Mengosongkan textbox dan masked edit
T_Kode.Text = ""
T_Nama.Text = ""
T_Ukuran.Text = ""
Cbo_Satuan.Text = "UNIT"
T_HrgJual.Text = ""
T_stockawal.Text = ""
T_StockMax.Text = ""
T_StockMin.Text = ""
End Sub
'
Private Sub cbo_satuan_KeyPress(keyascii As Integer)
keyascii = AutoComplete(Cbo_Satuan, keyascii, True, Asli)
'Pembacaan tombol Enter
If keyascii = 13 Then
'Menjalankan fungsi TAB
SendKeys vbTab
Else
'Membuat huruf besar
keyascii = Asc(UCase(Chr(keyascii)))
End If
End Sub
Private Sub t_cari_Change()
On Error GoTo SalahCari
If Cbo_cari.ListIndex = 0 Or Cbo_cari.Text = "Kode Bahan Baku" Then
ADO_BRG.RecordSource = "select * from Barang where kd_Barang like '%" & t_cari.Text & "%'"
ADO_BRG.Refresh
ElseIf Cbo_cari.ListIndex = 1 Then
ADO_BRG.RecordSource = "select * from Barang where namaBarang like '%" & t_cari.Text & "%'"
ADO_BRG.Refresh
ElseIf Cbo_cari.ListIndex = 2 Then
ADO_BRG.RecordSource = "select * from Barang where ukuran like '%" & t_cari.Text & "%'"
ADO_BRG.Refresh
ElseIf Cbo_cari.ListIndex = 3 Then
ADO_BRG.RecordSource = "select * from Barang where Satuan like '%" & t_cari.Text & "%'"
ADO_BRG.Refresh
ElseIf Cbo_cari.ListIndex = 4 Then
ADO_BRG.RecordSource = "select * from Barang where HargaJualBarang = " & Val(t_cari.Text) & ""
ADO_BRG.Refresh
ElseIf Cbo_cari.ListIndex = 5 Then
ADO_BRG.RecordSource = "select * from Barang where stockawal = " & Val(t_cari.Text) & ""
ADO_BRG.Refresh
ElseIf Cbo_cari.ListIndex = 6 Then
ADO_BRG.RecordSource = "select * from Barang where stockmin = " & Val(t_cari.Text) & ""
ADO_BRG.Refresh
ElseIf Cbo_cari.ListIndex = 7 Then
ADO_BRG.RecordSource = "select * from Barang where stockmax = " & Val(t_cari.Text) & ""
ADO_BRG.Refresh
Exit Sub
SalahCari:
MsgBox "Error : " & Err & " " & Err.Description
End If
Call sambung
ADO_BRG.Refresh
L_count = "Jml Data : " & ADO_BRG.Recordset.RecordCount
ADO_BRG.Refresh
End Sub
Private Sub txt_data_Click()
txt_cari.Text = ""
End Sub
Private Sub t_cari_keypress(keyascii As Integer)
Dim sTemplate As String
sTemplate = "`~@#$%^&*()+|=\<,>?/;:'"""
If Cbo_cari.ListIndex = 4 _
Or Cbo_cari.ListIndex = 5 _
Or Cbo_cari.ListIndex = 6 _
Or Cbo_cari.ListIndex = 7 Then _
If (Not (keyascii >= Asc("0") & Chr(13) _
And keyascii <= Asc("9") & Chr(13) _
Or keyascii = vbKeyBack _
Or keyascii = vbKeyDelete)) Then
Beep
keyascii = 0
MsgBox "Data Harus Angka"
ElseIf keyascii = 46 Then
keyascii = 0
MsgBox "Data Harus Angka"
End If
End If
If InStr(1, sTemplate, Chr(keyascii)) > 0 Then _
keyascii = 0
keyascii = Asc(UCase(Chr(keyascii)))
'MsgBox "Maaf Tidak Boleh Menggunakan" + Chr(13) + "Karakter !#$%^&*()+|\/,;:\'`~="""
'Pembacaan tombol Enter
End Sub
Private Sub cbo_cari_KeyPress(keyascii As Integer)
keyascii = AutoComplete(Cbo_cari, keyascii, False, Asli)
End Sub
Private Sub cbo_Urut_keypress(keyascii As Integer)
keyascii = AutoComplete(cbo_Urut, keyascii, False, Asli)
End Sub
Private Sub cbo_Urut_click()
If cbo_Urut.ListIndex = 0 Then
ADO_BRG.RecordSource = "select * from Barang order by kd_Barang"
ADO_BRG.Refresh
ElseIf cbo_Urut.ListIndex = 1 Then
ADO_BRG.RecordSource = "select * from Barang order by namaBarang"
ADO_BRG.Refresh
ElseIf cbo_Urut.ListIndex = 2 Then
ADO_BRG.RecordSource = "select * from Barang order by ukuran"
ADO_BRG.Refresh
ElseIf cbo_Urut.ListIndex = 3 Then
ADO_BRG.RecordSource = "select * from Barang order by satuan"
ADO_BRG.Refresh
ElseIf cbo_Urut.ListIndex = 4 Then
ADO_BRG.RecordSource = "select * from Barang order by hargajualBarang"
ADO_BRG.Refresh
ElseIf cbo_Urut.ListIndex = 5 Then
ADO_BRG.RecordSource = "select * from Barang order by stockawal"
ADO_BRG.Refresh
ElseIf cbo_Urut.ListIndex = 6 Then
ADO_BRG.RecordSource = "select * from Barang order by stockmin"
ADO_BRG.Refresh
ElseIf cbo_Urut.ListIndex = 7 Then
ADO_BRG.RecordSource = "select * from Barang order by stockmax"
ADO_BRG.Refresh
End If
End Sub
Sub JumlahData()
Call sambung
ADO_BRG.Refresh
L_count = "Jml Data : " & ADO_BRG.Recordset.RecordCount
ADO_BRG.Refresh
End Sub
Private Sub DG_input_dblclick()
'mengambil data kode brg dari grid
T_Kode.Text = DG_Input.Columns(0).Text
Cmd_Edit.Enabled = True
Call ambilDtaGrid
Call TidakTampak
End Sub
Private Sub DG_data_dblclick()
'mengambil data kode brg dari grid
T_Kode.Text = DG_Input.Columns(0).Text
Call ambilDtaGrid
Call TidakTampak
End Sub
Sub TidakTampak()
T_Kode.Enabled = False
T_Nama.Enabled = False
T_Ukuran.Enabled = False
T_stockawal.Enabled = False
T_HrgJual.Enabled = False
T_StockMax.Enabled = False
T_StockMin.Enabled = False
Cbo_Satuan.Enabled = False
End Sub
Sub ambilDtaGrid()
'Menampilkan di Data
Call sambung
sql = "select * from Barang where kd_Barang='" & T_Kode.Text & "'"
Set rs = Conn.Execute(sql)
If Not rs.EOF Then
T_Nama = rs("namaBarang")
T_Ukuran = rs("ukuran")
T_stockawal = rs("stockawal")
Cbo_Satuan.Text = rs("Satuan")
T_HrgJual.Text = rs("hargajualBarang")
T_stockawal.Text = rs("stockawal")
T_StockMax.Text = rs("StockMax")
T_StockMin.Text = rs("StockMin")
End If
End Sub
Kontrol
|
Properties
|
Nilai
|
Form1
|
Name
Caption
Font
Font size
Font style
Picture
|
Frm_login
SIA – MASTER BARANG
Arial
10
Standard
[ambil dari komputer gambar yang sudah
Anda download]
|
Frame
|
Name
Caption
|
Frame1
DATA BARANG
|
SSTab
|
Name
Tabs
TabPerRow
|
SSTab1
2
2
|
Pengaturan Custom pada objek SSTab
seperti gambar di bawah ini.
|
||
Label1
|
Name
Caption
Font
Font size
Font style
|
Label1
Kode Barang
Arial
10
Standard
|
Label2
|
Name
Caption
Font
Font Size
Font Style
|
Label2
Nama Barang
Arial
10
Standard
|
Label3
|
Name
Caption
Font
Font Size
Font Style
|
Label3
Ukuran
Arial
10
Standard
|
Label4
|
Name
Caption
Font
Font Size
Font Style
|
Label4
Satuan
Arial
10
Standard
|
Label5
|
Name
Caption
Font
Font Size
Font Style
|
Label5
Harga Jual
Arial
10
Standard
|
Label6
|
Name
Caption
Font
Font Size
Font Style
|
Label6
Stock Awal
Arial
10
Standard
|
Label7
|
Name
Caption
Font
Font Size
Font Style
|
Label7
Stock Minimal
Arial
10
Standard
|
Label8
|
Name
Caption
Font
Font Size
Font Style
|
Label8
Stock Max
Arial
10
Standard
|
TextBox1
|
Name
Font
Font Size
Font Style
Text
|
T_Kode
Arial
10
Standard
[dikosongkan]
|
TextBox2
|
Name
Font
Font Size
Font Style
Text
|
T_Nama
Arial
10
Standard
[dikosongkan]
|
TextBox3
|
Name
Font
Font Size
Font Style
Text
|
T_Ukuran
Arial
10
Standard
[dikosongkan]
|
ComboBox
|
Name
Font
Font Size
Font Style
Text
List
|
Cbo_Satuan
Arial
10
Standard
PCS
PCS
BOX
UNIT
GR
KG
|
MaskEditBox
|
Name
DataFormat
Font
Font Size
Font Style
Format
PromptChar
|
T_HrgJual
Currency
Arial
10
Standard
Rp #,##0
_
|
TextBox4
|
Name
Font
Font Size
Font Style
Text
|
T_StockAwal
Arial
10
Standard
[dikosongkan]
|
TextBox5
|
Name
Font
Font Size
Font Style
Text
|
T_StockMin
Arial
10
Standard
[dikosongkan]
|
TextBox6
|
Name
Font
Font Size
Font Style
Text
|
T_StockMax
Arial
10
Standard
[dikosongkan]
|
DataGrid
|
Name
Font
Font Size
Font Style
|
DG_Input
Arial
10
Standard
|
Adodc
|
Name
ConnectionString
|
ADOBRG
Provider=MSDASQL.1;Persist Security
Info=False;User ID=root;Data Source=DBSIARETAIL;Initial Catalog=dbsiaretail
|
CommandButton1
|
Name
Caption
Font
Font Size
Font Style
|
Cmd_Cari
&Cari
Verdana
10
Standard
|
CommandButton2
|
Name
Caption
Font
Font Size
Font Style
|
Cmd_Tambah
&Tambah
Verdana
10
Standard
|
CommandButton3
|
Name
Caption
Font
Font Size
Font Style
|
Cmd_Batal
&Batal
Verdana
10
Standard
|
CommandButton4
|
Name
Caption
Font
Font Size
Font Style
|
Cmd_Cetak
Ceta&k
Verdana
10
Standard
|
CommandButton5
|
Name
Caption
Font
Font Size
Font Style
|
Cmd_Simpan
&Simpan
Verdana
10
Standard
|
CommandButton6
|
Name
Caption
Font
Font Size
Font Style
|
Cmd_Edit
&Edit
Verdana
10
Standard
|
CommandButton7
|
Name
Caption
Font
Font Size
Font Style
|
Cmd_Hapus
&Hapus
Verdana
10
Standard
|
CommandButton8
|
Name
Caption
Font
Font Size
Font Style
|
Cmd_Tutup
TUTUP
Verdana
10
Standard
|
Isi dari SSTab(1) TABEL DATA BARANG.
|
||
Label9
|
Name
Caption
Font
Font size
Font style
|
Label9
Urutan
Arial
10
Standard
|
Label10
|
Name
Caption
Font
Font Size
Font Style
|
Label10
Cari Berdasarkan
Arial
10
Standard
|
Label11
|
Name
Caption
Font
Font Size
Font Style
|
Label11
Cari Data
Arial
10
Standard
|
ComboBox
|
Name
Font
Font Size
Font Style
Text
List
|
Cbo_Urut
Arial
10
Standard
Kode Barang
Kode
Barang
Nama
Ukuran
Satuan
Harga
Jual
|
ComboBox
|
Name
Font
Font Size
Font Style
Text
List
|
Cbo_Cari
Arial
10
Standard
Kode Barang
Kode
Barang
Nama
Ukuran
Satuan
Harga
Jual
|
TextBox7
|
Name
Font
Font Size
Font Style
Text
|
T_Cari
Arial
10
Standard
[dikosongkan]
|
DataGrid
|
Name
Font
Font Size
Font Style
|
DG_Data
Arial
10
Standard
|
Selanjutnya Tuliskan Kode Programnya seperti berikut.
KODE PROGRAM Module Login
|
'Deklarasi koneksi dan recordset Dim cnn As New ADODB.Connection Dim rs As New ADODB.Recordset Private Sub cmd_tutup_Click() Unload Me End Sub Private Sub Form_Activate() 'Ukuran dan posisi form Me.Top = 100 Me.Left = 1000 ADO_BRG.Refresh End Sub Private Sub Form_Load() Call JumlahData End Sub Private Sub Cmd_Batal_Click() T_Kode.Enabled = True T_Nama.Enabled = True T_Ukuran.Enabled = True T_stockawal.Enabled = True T_HrgJual.Enabled = True T_StockMax.Enabled = True T_StockMin.Enabled = True Cbo_Satuan.Enabled = True Call Kosong Cmd_Edit.Enabled = False Cmd_Hapus.Enabled = False Cmd_Batal.Enabled = False Cmd_Tambah.Enabled = True End Sub Private Sub Cmd_Hapus_click() Dim sql As String Dim konfirmasi As String On Error GoTo SalahHapus If T_Kode.Text <> "" And T_Kode.Enabled = False Then konfirmasi = MsgBox("Mau Hapus Record???", vbYesNo + vbCritical, "Konfirmasi") If konfirmasi = vbYes Then 'Menghapus record pada tabel sql = "Delete From Barang " & _ " Where kd_Barang='" & T_Kode.Text & "'" 'Mengeksekusi perintah SQL Conn.Execute (sql) T_Kode.Enabled = True T_Nama.Enabled = True Cbo_Satuan.Enabled = True T_HrgJual.Enabled = True T_stockawal.Enabled = True T_StockMin.Enabled = True T_StockMax.Enabled = True T_Ukuran.Enabled = True Cmd_Tambah.Enabled = True Cmd_Simpan.Enabled = False Cmd_Hapus.Enabled = False Cmd_Edit.Enabled = True Cmd_Batal.Enabled = True Call Kosong Call sambung Call JumlahData End If End If ADO_BRG.Refresh Exit Sub SalahHapus: Select Case Err.Number Case -2147217900 errmsg = " Data Masih Terhubung Oleh Tabel Lain " & vbCrLf Case Else errmsg = Err.Description End Select MsgBox errmsg, vbCritical + vbOKOnly, "Informasi:" End Sub Private Sub cmd_Keluar_Click() 'Keluar dari form Unload Me End Sub Private Sub cmd_Simpan_Click() Dim sql As String Dim panjang As Byte panjang = Len(T_Kode.Text) On Error GoTo SalahIsi If T_Kode.Text = "" Or T_Nama.Text = "" Or T_Ukuran = "" Or Cbo_Satuan = "" Or T_HrgJual = "" Or T_stockawal = "" Or T_StockMax = "" Or T_StockMin = "" Then MsgBox "Data Belum Lengkap", vbOKOnly, "Data" ElseIf panjang < 5 Then MsgBox "Kode Barang Minimal 5 Digit", vbCritical + vbOKOnly, "Kode Barang" ElseIf Val(T_StockMax.Text) < Val(T_StockMin.Text) _ Then MsgBox " Jumlah Stock Max Sama " + Chr(13) + "atau lebih dari Stock Min" T_StockMax.SetFocus T_StockMax.Text = "" ElseIf T_Kode.Text <> "" And T_Nama.Text <> "" And T_Ukuran.Text <> "" And Cbo_Satuan.Text <> "" And T_HrgJual.Text <> "" And T_stockawal <> "" And T_StockMax.Text <> "" And T_StockMin.Text <> "" _ And Val(T_StockMax.Text) >= Val(T_StockMin.Text) And panjang >= 5 Then If T_Kode.Enabled = True Then 'Menambah record pada tabel sql = "Insert into Barang Values('" & T_Kode.Text & "','" & T_Nama.Text & "','" & T_Ukuran.Text & "','" & Cbo_Satuan.Text & " '," & Val(T_HrgJual.Text) & "," & Val(T_stockawal.Text) & "," & Val(T_StockMin.Text) & "," & Val(T_StockMax.Text) & ") " 'Mengeksekusi perintah SQL Conn.Execute (sql) Call sambung ADO_BRG.Refresh Call sambung Call JumlahData Else 'Mengubah record pada tabel sql = "Update Barang set " & _ " NamaBarang='" & T_Nama.Text & "'," & _ " Ukuran='" & T_Ukuran.Text & "'," & _ " satuan='" & Cbo_Satuan.Text & "'," & _ " HargaJualBarang=" & T_HrgJual.Text & "," & _ " stockAwal=" & T_stockawal.Text & "," & _ " stockmin=" & T_StockMin.Text & "," & _ " stockmax=" & T_StockMax.Text & " Where Kd_Barang='" & T_Kode.Text & "'" 'Mengeksekusi perintah SQL Conn.Execute (sql) End If T_Kode.Enabled = False T_Nama.Enabled = False Cbo_Satuan.Enabled = False T_HrgJual.Enabled = False T_stockawal.Enabled = False T_StockMin.Enabled = False T_StockMax.Enabled = False T_Ukuran.Enabled = False Cmd_Simpan.Enabled = False Cmd_Batal.Enabled = False Cmd_Tambah.Enabled = True Cmd_Hapus.Enabled = True Cmd_Edit.Enabled = True End If ADO_BRG.Refresh ADO_BRG.Recordset.MoveLast Exit Sub SalahIsi: Select Case Err.Number Case -2147217833 errmsg = " Angka Yang Anda Masukaan Terlalu Banyak " & vbCrLf Case Else errmsg = Err.Description End Select MsgBox errmsg, vbCritical + vbOKOnly, "Informasi:" 'MsgBox "Error:" & Err & "" & Err.Description End Sub Private Sub cmd_Tambah_Click() T_Kode.Enabled = True T_Nama.Enabled = True Cbo_Satuan.Enabled = True T_HrgJual.Enabled = True T_stockawal.Enabled = True T_StockMin.Enabled = True T_StockMax.Enabled = True T_Ukuran.Enabled = True Cmd_Tambah.Enabled = False Cmd_Simpan.Enabled = True Cmd_Edit.Enabled = False Cmd_Hapus.Enabled = False Cmd_Batal.Enabled = True Call Kosong T_Kode.SetFocus End Sub Private Sub cmd_edit_Click() Dim sql As String If T_Kode.Text <> "" And T_Kode.Enabled = False Then T_Nama.Enabled = True Cbo_Satuan.Enabled = True T_HrgJual.Enabled = True T_stockawal.Enabled = True T_StockMin.Enabled = True T_StockMax.Enabled = True T_Ukuran.Enabled = True End If Cmd_Edit.Enabled = False Cmd_Hapus.Enabled = False Cmd_Simpan.Enabled = True End Sub Private Sub Form_Unload(Cancel As Integer) 'Menutup koneksi Set Conn = Nothing End Sub Private Sub T_hrgjual_keypress(keyascii As Integer) If Not (keyascii >= Asc("0") & Chr(13) _ And keyascii <= Asc("9") & Chr(13) _ Or keyascii = vbKeyBack _ Or keyascii = vbKeyDelete) And Not (keyascii = 13) Then Beep keyascii = 0 MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan" ElseIf keyascii = 46 Then keyascii = 0 MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan" ElseIf keyascii = 13 Then SendKeys vbTab End If End Sub Private Sub t_Kode_KeyPress(keyascii As Integer) Dim sTemplate As String 'Ganti '!@#$%^&*()_+=' dengan karakter yang Anda 'inginkan untuk dihindari diinput pada Text1 sTemplate = "`~@#$%^&*()_+|=\<,>?/;:'""" If InStr(1, sTemplate, Chr(keyascii)) > 0 Then _ keyascii = 0 'Pembacaan tombol Enter If keyascii = 13 Then 'Menjalankan fungsi TAB SendKeys vbTab Else 'Membuat huruf besar keyascii = Asc(UCase(Chr(keyascii))) End If End Sub Private Sub t_Kode_LostFocus() Dim sql As String Call sambung If T_Kode.Text <> "" Then 'Mencari Kode pada tabel sql = "select * from Barang " & _ " where kd_Barang='" & T_Kode.Text & "'" Set rs = Conn.Execute(sql) 'Jika Kode sudah ada If Not rs.EOF Then 'Menampilkan field yang lain T_Nama.Text = rs.Fields("NamaBarang") T_Ukuran.Text = rs.Fields("ukuran") Cbo_Satuan.Text = rs.Fields("satuan") T_HrgJual.Text = rs.Fields("HargaJualBarang") T_stockawal.Text = rs.Fields("stockawal") T_StockMin.Text = rs.Fields("stockmin") T_StockMax.Text = rs.Fields("stockmax") T_Kode.Enabled = False T_Nama.Enabled = False T_Ukuran.Enabled = False Cbo_Satuan.Enabled = False T_HrgJual.Enabled = False T_stockawal.Enabled = False T_StockMin.Enabled = False T_StockMax.Enabled = False Cmd_Tambah.Enabled = True Cmd_Hapus.Enabled = True Cmd_Edit.Enabled = True Else Cmd_Simpan.Enabled = True Cmd_Batal.Enabled = True End If rs.Close End If End Sub Private Sub Cmd_Cari_click() Dim sql As String Call sambung If T_Kode.Text = "" Then MsgBox "Masukkan Data yang Akan Dicari" T_Kode.SetFocus ElseIf T_Kode.Text <> "" Then 'Mencari Kode pada tabel sql = "select * from Barang " & _ " where kd_Barang='" & T_Kode.Text & "'" Set rs = Conn.Execute(sql) 'Jika Kode sudah ada If Not rs.EOF Then 'Menampilkan field yang lain T_Nama.Text = rs.Fields("NamaBarang") T_Ukuran.Text = rs.Fields("ukuran") Cbo_Satuan.Text = rs.Fields("satuan") T_HrgJual.Text = rs.Fields("HargaJualBarang") T_stockawal.Text = rs.Fields("stockawal") T_StockMin.Text = rs.Fields("stockmin") T_StockMax.Text = rs.Fields("stockmax") T_Kode.Enabled = False T_Nama.Enabled = False T_Ukuran.Enabled = False Cbo_Satuan.Enabled = False T_HrgJual.Enabled = False T_stockawal.Enabled = False T_StockMin.Enabled = False T_StockMax.Enabled = False Cmd_Tambah.Enabled = True Cmd_Hapus.Enabled = True Cmd_Edit.Enabled = True Else Cmd_Simpan.Enabled = True Cmd_Batal.Enabled = True End If If rs.EOF Then MsgBox "Data yang Anda Cari Tidak Ada", vbInformation, "Data Tidak Ada" T_Kode.Text = "" T_Kode.SetFocus rs.Close End If End If End Sub Private Sub t_Nama_KeyPress(keyascii As Integer) Dim sTemplate As String 'Ganti '!@#$%^&*()_+=' dengan karakter yang Anda 'inginkan untuk dihindari diinput pada Text1 sTemplate = "`~@#$%^&*()+|=\<,>?/;:'""" If InStr(1, sTemplate, Chr(keyascii)) > 0 Then _ keyascii = 0 'Pembacaan tombol Enter If keyascii = 13 Then 'Menjalankan fungsi TAB SendKeys vbTab Else 'Membuat huruf besar keyascii = Asc(UCase(Chr(keyascii))) End If End Sub Private Sub t_ukuran_KeyPress(keyascii As Integer) Dim sTemplate As String 'Ganti '!@#$%^&*()_+=' dengan karakter yang Anda 'inginkan untuk dihindari diinput pada Text1 sTemplate = "`~@#$^&*()_+|=\<,>?/;:'""" If InStr(1, sTemplate, Chr(keyascii)) > 0 Then _ keyascii = 0 'Pembacaan tombol Enter If keyascii = 13 Then 'Menjalankan fungsi TAB SendKeys vbTab Else 'Membuat huruf besar keyascii = Asc(UCase(Chr(keyascii))) End If End Sub Private Sub T_stockawal_keypress(keyascii As Integer) ''If Not (keyascii >= Asc("0") & Chr(13) _ '' And keyascii <= Asc("9") & Chr(13) _ '' Or keyascii = vbKeyBack _ '' Or keyascii = vbKeyDelete) And Not (keyascii = 13) Then '' Beep '' keyascii = 0 '' MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan" '' ElseIf keyascii = 46 Then '' keyascii = 0 '' MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan" ''Else If keyascii = 13 Then SendKeys vbTab End If End Sub Private Sub T_stockmin_keypress(keyascii As Integer) ''If Not (keyascii >= Asc("0") & Chr(13) _ '' And keyascii <= Asc("9") & Chr(13) _ '' Or keyascii = vbKeyBack _ '' Or keyascii = vbKeyDelete) And Not (keyascii = 13) Then '' Beep '' keyascii = 0 '' MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan" '' ElseIf keyascii = 46 Then '' keyascii = 0 '' MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan" ''Else If keyascii = 13 Then SendKeys vbTab End If End Sub Private Sub T_stockmax_keypress(keyascii As Integer) ''If Not (keyascii >= Asc("0") & Chr(13) _ '' And keyascii <= Asc("9") & Chr(13) _ '' Or keyascii = vbKeyBack _ '' Or keyascii = vbKeyDelete) And Not (keyascii = 13) Then '' Beep '' keyascii = 0 '' MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan" '' ElseIf keyascii = 46 Then '' keyascii = 0 '' MsgBox " Data Harus Angka dan" + Chr(13) + "Tidak Mengandung Pecahan" ''Else If keyascii = 13 Then SendKeys vbTab End If End Sub Sub Kosong() 'Mengosongkan textbox dan masked edit T_Kode.Text = "" T_Nama.Text = "" T_Ukuran.Text = "" Cbo_Satuan.Text = "UNIT" T_HrgJual.Text = "" T_stockawal.Text = "" T_StockMax.Text = "" T_StockMin.Text = "" End Sub ' Private Sub cbo_satuan_KeyPress(keyascii As Integer) keyascii = AutoComplete(Cbo_Satuan, keyascii, True, Asli) 'Pembacaan tombol Enter If keyascii = 13 Then 'Menjalankan fungsi TAB SendKeys vbTab Else 'Membuat huruf besar keyascii = Asc(UCase(Chr(keyascii))) End If End Sub Private Sub t_cari_Change() On Error GoTo SalahCari If Cbo_cari.ListIndex = 0 Or Cbo_cari.Text = "Kode Bahan Baku" Then ADO_BRG.RecordSource = "select * from Barang where kd_Barang like '%" & t_cari.Text & "%'" ADO_BRG.Refresh ElseIf Cbo_cari.ListIndex = 1 Then ADO_BRG.RecordSource = "select * from Barang where namaBarang like '%" & t_cari.Text & "%'" ADO_BRG.Refresh ElseIf Cbo_cari.ListIndex = 2 Then ADO_BRG.RecordSource = "select * from Barang where ukuran like '%" & t_cari.Text & "%'" ADO_BRG.Refresh ElseIf Cbo_cari.ListIndex = 3 Then ADO_BRG.RecordSource = "select * from Barang where Satuan like '%" & t_cari.Text & "%'" ADO_BRG.Refresh ElseIf Cbo_cari.ListIndex = 4 Then ADO_BRG.RecordSource = "select * from Barang where HargaJualBarang = " & Val(t_cari.Text) & "" ADO_BRG.Refresh ElseIf Cbo_cari.ListIndex = 5 Then ADO_BRG.RecordSource = "select * from Barang where stockawal = " & Val(t_cari.Text) & "" ADO_BRG.Refresh ElseIf Cbo_cari.ListIndex = 6 Then ADO_BRG.RecordSource = "select * from Barang where stockmin = " & Val(t_cari.Text) & "" ADO_BRG.Refresh ElseIf Cbo_cari.ListIndex = 7 Then ADO_BRG.RecordSource = "select * from Barang where stockmax = " & Val(t_cari.Text) & "" ADO_BRG.Refresh Exit Sub SalahCari: MsgBox "Error : " & Err & " " & Err.Description End If Call sambung ADO_BRG.Refresh L_count = "Jml Data : " & ADO_BRG.Recordset.RecordCount ADO_BRG.Refresh End Sub Private Sub txt_data_Click() txt_cari.Text = "" End Sub Private Sub t_cari_keypress(keyascii As Integer) Dim sTemplate As String sTemplate = "`~@#$%^&*()+|=\<,>?/;:'""" If Cbo_cari.ListIndex = 4 _ Or Cbo_cari.ListIndex = 5 _ Or Cbo_cari.ListIndex = 6 _ Or Cbo_cari.ListIndex = 7 Then _ If (Not (keyascii >= Asc("0") & Chr(13) _ And keyascii <= Asc("9") & Chr(13) _ Or keyascii = vbKeyBack _ Or keyascii = vbKeyDelete)) Then Beep keyascii = 0 MsgBox "Data Harus Angka" ElseIf keyascii = 46 Then keyascii = 0 MsgBox "Data Harus Angka" End If End If If InStr(1, sTemplate, Chr(keyascii)) > 0 Then _ keyascii = 0 keyascii = Asc(UCase(Chr(keyascii))) 'MsgBox "Maaf Tidak Boleh Menggunakan" + Chr(13) + "Karakter !#$%^&*()+|\/,;:\'`~=""" 'Pembacaan tombol Enter End Sub Private Sub cbo_cari_KeyPress(keyascii As Integer) keyascii = AutoComplete(Cbo_cari, keyascii, False, Asli) End Sub Private Sub cbo_Urut_keypress(keyascii As Integer) keyascii = AutoComplete(cbo_Urut, keyascii, False, Asli) End Sub Private Sub cbo_Urut_click() If cbo_Urut.ListIndex = 0 Then ADO_BRG.RecordSource = "select * from Barang order by kd_Barang" ADO_BRG.Refresh ElseIf cbo_Urut.ListIndex = 1 Then ADO_BRG.RecordSource = "select * from Barang order by namaBarang" ADO_BRG.Refresh ElseIf cbo_Urut.ListIndex = 2 Then ADO_BRG.RecordSource = "select * from Barang order by ukuran" ADO_BRG.Refresh ElseIf cbo_Urut.ListIndex = 3 Then ADO_BRG.RecordSource = "select * from Barang order by satuan" ADO_BRG.Refresh ElseIf cbo_Urut.ListIndex = 4 Then ADO_BRG.RecordSource = "select * from Barang order by hargajualBarang" ADO_BRG.Refresh ElseIf cbo_Urut.ListIndex = 5 Then ADO_BRG.RecordSource = "select * from Barang order by stockawal" ADO_BRG.Refresh ElseIf cbo_Urut.ListIndex = 6 Then ADO_BRG.RecordSource = "select * from Barang order by stockmin" ADO_BRG.Refresh ElseIf cbo_Urut.ListIndex = 7 Then ADO_BRG.RecordSource = "select * from Barang order by stockmax" ADO_BRG.Refresh End If End Sub Sub JumlahData() Call sambung ADO_BRG.Refresh L_count = "Jml Data : " & ADO_BRG.Recordset.RecordCount ADO_BRG.Refresh End Sub Private Sub DG_input_dblclick() 'mengambil data kode brg dari grid T_Kode.Text = DG_Input.Columns(0).Text Cmd_Edit.Enabled = True Call ambilDtaGrid Call TidakTampak End Sub Private Sub DG_data_dblclick() 'mengambil data kode brg dari grid T_Kode.Text = DG_Input.Columns(0).Text Call ambilDtaGrid Call TidakTampak End Sub Sub TidakTampak() T_Kode.Enabled = False T_Nama.Enabled = False T_Ukuran.Enabled = False T_stockawal.Enabled = False T_HrgJual.Enabled = False T_StockMax.Enabled = False T_StockMin.Enabled = False Cbo_Satuan.Enabled = False End Sub Sub ambilDtaGrid() 'Menampilkan di Data Call sambung sql = "select * from Barang where kd_Barang='" & T_Kode.Text & "'" Set rs = Conn.Execute(sql) If Not rs.EOF Then T_Nama = rs("namaBarang") T_Ukuran = rs("ukuran") T_stockawal = rs("stockawal") Cbo_Satuan.Text = rs("Satuan") T_HrgJual.Text = rs("hargajualBarang") T_stockawal.Text = rs("stockawal") T_StockMax.Text = rs("StockMax") T_StockMin.Text = rs("StockMin") End If End Sub |
Selanjutnya Anda Simpan kembali project Anda, lalu Anda jalankan project Anda dan coba buka Form Master Barang melalui Menu Utama.
Pembahasan berikutnya adalah membuat form Transaksi Pembelian Barang. Silahkan klik tombol dibawah ini untuk Tutorial Pembahasan Transaksi Pembelian Barang.
Klik Untuk Lanjut ke Pembahasan Berikutnya |
No comments:
Post a Comment