Membuat Form Transaksi

Form Transaksi kita dalam Aplikasi Inventori, terbagi menjadi 2 yaitu,
1. Transaksi pembelian barang atau mutasi barang masuk
2. Transaksi penjualan atau mutasi barang keluar

Untuk melengkapi kebutuhan tersebut kita harus menyediakan tabel tambahan sebanyak 4 buah
dengan spesifikasi sbb :
1. tbNotaBeli
2. tbNotaBeliDetail
3. tbNotaJual
4. tbNotaJualDetail

berikut struktur tablenya

Table Name : tbNotaBeli



No. Field Name Type Data Length Description Allow Nulls
1 NoNota text 10 0
2 Tanggal date/time 0
3 KodePemasok text 10
4 NamaPemasok text 50
5 SubTotal number Double
6 Potongan number Double
7 TotalAkhir number Double
8 Keterangan text 25






Table Name : tbNotaBeliDetail


No. Field Name Type Data Length Description Allow Nulls
1 NoNota text 10
2 KodeBarang text 10
3 NamaBarang text 50
4 HargaBeli number double
5 Satuan text 10
6 Jumlah number double
7 Total number double






Table Name : tbNotaJual



No. Field Name Type Data Length Description Allow Nulls
1 NoNota text 10 0
2 Tanggal date/time 0
3 KodePelanggan text 10
4 NamaPelanggan text 50
5 SubTotal number Double
6 Potongan number Double
7 TotalAkhir number Double
8 Keterangan text 25






Table Name : tbNotaJualDetail


No. Field Name Type Data Length Description Allow Nulls
1 NoNota text 10
2 KodeBarang text 10
3 NamaBarang text 50
4 HargaBeli number double
5 Satuan text 10
6 Jumlah number double
7 Total number double
Sekarang kita buat form pembelian, berikut layout form pembelian


Cara membuat form pembelian, komponen yang kita butuhkan antara lain
==> DTPicker untuk tanggal
==> ADO Data Control
==> Data Grid
==> Label dan TextBox
==> Masked Edit Box

Tambahkan form baru dan simpan dengan nama frm_beli, atur layout seperti gambar diatas.
Berikut Script untuk form pembelian.

Dim Cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset

'Total Pembelian
Dim Total As Double

Private Sub CmdBatal_Click()
Dim Msql As String

TNota.Enabled = True
TKPemasok.Enabled = True
TNPemasok.Enabled = True
TKeterangan.Enabled = True
MseSubTotal.Enabled = True
MsePotongan.Enabled = True
MseTotal.Enabled = True

TKBarang.Enabled = True
TNBarang.Enabled = True
TSatuan.Enabled = True
MseHarga.Enabled = True
MseJumlah.Enabled = True

'Menghapus record pada tabel
Msql = "Delete From tbNotaBeliDetail " & _
" Where NoNota='" & TNota.Text & "'"

'Mengeksekusi perintah SQL
Cnn.Execute (Msql)

Call Kosong
Call Detail

CmdHapus.Enabled = False
CmdBatal.Enabled = False
CmdSimpan.Enabled = False

End Sub

Private Sub CmdHapus_Click()
Dim Konfirmasi, KodeBrg, NamaBrg, Satuan As String
Dim Jumlah As Double
Dim rs1 As New ADODB.Recordset
Dim Msql As String

If TNota.Text <> "" And TNota.Enabled = False Then
Cnn.BeginTrans

Konfirmasi = MsgBox("Mau Hapus Record ???", vbYesNo + vbCritical, "Konfirmasi")
If Konfirmasi = vbYes Then
'Mencari No Nota
Msql = "Select * From tbNotaBeliDetail " & _
" Where NoNota='" & TNota.Text & "'"

Set rs = Cnn.Execute(Msql)

'Jika No. Nota ditemukan
If Not rs.EOF Then
rs.MoveFirst

Do While Not rs.EOF

KodeBrg = rs.Fields("KodeBarang")
Jumlah = rs.Fields("Jumlah")

'Mencari Kode Barang pada Stok
Msql = "Select * From tbStok " & _
" Where KodeBarang='" & KodeBrg & "'"

Set rs1 = Cnn.Execute(Msql)

'Jika Kode Barang ditemukan
If Not rs1.EOF Then

'Mengurangi Jumlah Stok Barang
Msql = "Update tbStok Set " & _
" Jumlah=Jumlah - " & Val(Jumlah) & "" & _
"Where KodeBarang='" & KodeBrg & "'"

Cnn.Execute (Msql)
End If
rs1.Close

If Not rs.EOF Then
rs.MoveNext
End If
Loop
End If

rs.Close

'Menghapus record pada tabel NotaBeli
Msql = "Delete From tbNotaBeli " & _
" Where NoNota='" & TNota.Text & "'"

'Mengeksekusi perintah SQL
Cnn.Execute (Msql)

'Menghapus record pada tabel NotaBeliDetail
Msql = "Delete From tbNotaBeliDetail " & _
" Where NoNota='" & TNota.Text & "'"

'Mengeksekusi perintah SQL
Cnn.Execute (Msql)

TNota.Enabled = True
TKPemasok.Enabled = True
TNPemasok.Enabled = True
TKeterangan.Enabled = True
MseSubTotal.Enabled = True
MsePotongan.Enabled = True
MseTotal.Enabled = True

TKBarang.Enabled = True
TNBarang.Enabled = True
TSatuan.Enabled = True
MseHarga.Enabled = True
MseJumlah.Enabled = True

CmdTambah.Enabled = False
CmdSimpan.Enabled = False
CmdHapus.Enabled = False
CmdBatal.Enabled = False

Call Kosong
Call Detail

Cnn.CommitTrans
End If

End If
End Sub

Private Sub CmdSelesai_Click()

Set rs = Nothing
Set rs1 = Nothing

Unload Me

Call Menu_Bisa

End Sub

Private Sub CmdSimpan_Click()
Dim KodeBrg, NamaBrg, Satuan As String
Dim Jumlah As Double
Dim rs1 As New ADODB.Recordset
Dim Msql As String

If TNota.Text <> "" Then
Cnn.BeginTrans

'Mencari No Nota
Msql = " Select * From tbNotaBeliDetail " & _
" Where NoNota='" & TNota.Text & "'"

Set rs = Cnn.Execute(Msql)

'Jika No. Nota ditemukan
If Not rs.EOF Then
rs.MoveFirst

Do While Not rs.EOF

KodeBrg = rs.Fields("KodeBarang")
NamaBrg = rs.Fields("NamaBarang")
Satuan = rs.Fields("Satuan")
Jumlah = rs.Fields("Jumlah")

'Mencari Kode Barang pada Stok
Msql = "Select * From tbStok " & _
" Where KodeBarang='" & KodeBrg & "'"

Set rs1 = Cnn.Execute(Msql)

'Jika Kode Barang tidak ditemukan
If rs1.EOF Then

'Isi Jumlah Barang pada Stok
Msql = "Insert Into tbStok (KodeBarang, NamaBarang, " & _
" Satuan, Jumlah) " & _
" Values('" & KodeBrg & "','" & NamaBrg & "'," & _
"'" & Satuan & "'," & Val(Jumlah) & ")"

Cnn.Execute (Msql)

'Jika Kode Barang ada
Else
'Ubah Jumlah Barang pada Stok
Msql = "Update tbStok set " & _
" Jumlah=Jumlah + " & Val(Jumlah) & "" & _
" Where KodeBarang='" & KodeBrg & "'"

Cnn.Execute (Msql)

End If
rs1.Close

If Not rs.EOF Then
rs.MoveNext
End If

Loop
End If

rs.Close

'Menambah record pada tabel NotaBeli
Msql = "Insert into tbNotaBeli(NoNota, Tanggal, KodePemasok, " & _
" NamaPemasok, Keterangan, SubTotal, Potongan, TotalAkhir) " & _
" Values('" & TNota.Text & "','" & dpTanggal.Value & "', " & _
" '" & TKPemasok.Text & "','" & TNPemasok.Text & "'," & _
" '" & TKeterangan.Text & "'," & Val(MseSubTotal.Text) & "," & _
" " & Val(MsePotongan.Text) & "," & Val(MseTotal.Text) & ")"

'Mengeksekusi perintah SQL
Cnn.Execute (Msql)

TNota.Enabled = False
TKPemasok.Enabled = False
TNPemasok.Enabled = False
TKeterangan.Enabled = False
MseSubTotal.Enabled = False
MsePotongan.Enabled = False
MseTotal.Enabled = False

TKBarang.Enabled = False
TNBarang.Enabled = False
TSatuan.Enabled = False
MseHarga.Enabled = False
MseJumlah.Enabled = False

CmdTambah.Enabled = True
CmdSimpan.Enabled = True

CmdHapus.Enabled = True
CmdBatal.Enabled = False


Cnn.CommitTrans
End If

End Sub

Private Sub CmdTambah_Click()

TNota.Enabled = True
TKPemasok.Enabled = True
TNPemasok.Enabled = True
TKeterangan.Enabled = True
MseSubTotal.Enabled = True
MsePotongan.Enabled = True
MseTotal.Enabled = True

TKBarang.Enabled = True
TNBarang.Enabled = True
TSatuan.Enabled = True
MseHarga.Enabled = True
MseJumlah.Enabled = True

CmdTambah.Enabled = False
CmdSimpan.Enabled = False
CmdHapus.Enabled = False
CmdBatal.Enabled = False

Call Kosong
Call Detail

TNota.SetFocus

End Sub

Private Sub Form_Activate()
TNota.SetFocus
End Sub

Private Sub Form_Load()
'Dim Koneksi As String

'Driver ODBC Connection String
'Koneksi = "Driver={Microsoft Access Driver(*.mdb)};" & _
' "Dbq=inventori.mdb;" & _
' "DefaultDir=D:\LatihanVB\Inventori;" & _
' "Uid=Admin;Pwd=;"

'Membuka Koneksi dengan ODBC Driver Aplikasi
'Cnn.Open Koneksi

Set Cnn = New ADODB.Connection

Cnn.Open "inventori"

Call Detail

dgDetail.Refresh

CmdTambah.Enabled = False
CmdSimpan.Enabled = False

CmdHapus.Enabled = False
CmdBatal.Enabled = False

Total = 0

Me.Top = (Main.ScaleHeight - Me.ScaleHeight) / 2
Me.Left = (Main.ScaleWidth - Me.ScaleWidth) / 2

End Sub

Private Sub Form_Unload(Cancel As Integer)
Cnn.Close

Set Cnn = Nothing
End Sub

Private Sub MseHarga_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
Dim StrAngka As String
StrAngka = "0123456789"

If KeyAscii > 26 Then
If InStr(StrAngka, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
End If
End Sub

Private Sub MseJumlah_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
Dim StrAngka As String
StrAngka = "0123456789"

If KeyAscii > 26 Then
If InStr(StrAngka, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
End If
End Sub

Private Sub MseJumlah_LostFocus()
Dim Msql As String
Dim TotalBrg As Double

If TKBarang.Text <> "" Then

Cnn.BeginTrans

'Total Harga Per Barang
TotalBrg = Val(MseHarga.Text) * Val(MseJumlah.Text)

'Total Harga Pembelian
Total = Total + TotalBrg

'Menambah Record pada Tabel NotaBeliDetail
Msql = "Insert into tbNotaBeliDetail(NoNota, KodeBarang," & _
" NamaBarang, HargaBeli, Satuan, Jumlah, Total)" & _
" Values('" & TNota.Text & "','" & TKBarang.Text & "','" & TNBarang.Text & "'," & Val(MseHarga.Text) & "," & _
" '" & TSatuan.Text & "'," & Val(MseJumlah.Text) & ", " & Val(TotalBrg) & ")"

Cnn.Execute (Msql)

Cnn.CommitTrans

Call Detail

TKBarang.SetFocus

TKBarang.Text = ""
TNBarang.Text = ""
TSatuan.Text = ""
MseHarga.Text = ""
MseJumlah.Text = ""

MseSubTotal.Text = Total
MseTotal.Text = Total

End If
End Sub

Private Sub MsePotongan_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
Dim StrAngka As String
StrAngka = "0123456789"

If KeyAscii > 26 Then
If InStr(StrAngka, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
End If
End Sub

Private Sub MsePotongan_LostFocus()

'Harga Sub Total dikurangi potongan
MseTotal.Text = Total - Val(MsePotongan.Text)

End Sub

Private Sub MseSubTotal_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
Dim StrAngka As String
StrAngka = "0123456789"

If KeyAscii > 26 Then
If InStr(StrAngka, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
End If
End Sub

Private Sub TKBarang_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub

Private Sub TKBarang_LostFocus()
Dim Msql As String

If TKBarang.Text <> "" Then

'Mencari Kode Barang
Msql = "Select * From tbBarang " & _
"Where Kode='" & TKBarang.Text & "'"

Set rs = Cnn.Execute(Msql)

'Jika Kode Barang Ada
If Not rs.EOF Then
TNBarang.Text = rs.Fields("Nama")
MseHarga.Text = rs.Fields("HargaBeli")
TSatuan.Text = rs.Fields("Satuan")
MseJumlah.SetFocus
End If
rs.Close
End If

End Sub

Private Sub TKeterangan_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub

Private Sub TKPemasok_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub

Private Sub TKPemasok_LostFocus()
Dim Msql As String

If TKPemasok.Text <> "" Then

'Mencari Kode Barang
Msql = "Select * From tbPemasok " & _
"Where Kode='" & TKPemasok.Text & "'"

Set rs = Cnn.Execute(Msql)

'Jika Kode Barang Ada
If Not rs.EOF Then
TNPemasok.Text = rs.Fields("Nama")
End If
rs.Close
End If

End Sub

Private Sub TNBarang_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub

Private Sub TNota_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub

Private Sub TNota_LostFocus()
Dim Msql As String

If TNota.Text <> "" Then

Cnn.BeginTrans

'Mencari NoNota pada tabel NotaBeli
Msql = "Select * From tbNotaBeli " & _
"Where NoNota='" & TNota.Text & "'"

Set rs = Cnn.Execute(Msql)

'Jika NoNota Ada
If Not rs.EOF Then
dpTanggal.Value = rs.Fields("Tanggal")
TKPemasok.Text = rs.Fields("KodePemasok")
TNPemasok.Text = rs.Fields("NamaPemasok")
TKeterangan.Text = rs.Fields("Keterangan")
MseSubTotal.Text = rs.Fields("SubTotal")
MsePotongan.Text = rs.Fields("Potongan")
MseTotal.Text = rs.Fields("TotalAkhir")

Call Detail

TNota.Enabled = False
TKPemasok.Enabled = False
TNPemasok.Enabled = False
TKeterangan.Enabled = False
MseSubTotal.Enabled = False
MsePotongan.Enabled = False
MseTotal.Enabled = False

TKBarang.Enabled = False
TNBarang.Enabled = False
TSatuan.Enabled = False
MseHarga.Enabled = False
MseJumlah.Enabled = False

CmdTambah.Enabled = True
CmdHapus.Enabled = True
CmdBatal.Enabled = True

Else

CmdSimpan.Enabled = True

End If

rs.Close

Cnn.CommitTrans

End If

End Sub

Private Sub TNPemasok_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub

Private Sub TSatuan_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub

Sub Kosong()
TNota.Text = ""
TKPemasok.Text = ""
TNPemasok.Text = ""
TKeterangan.Text = ""
MseSubTotal.Text = ""
MsePotongan.Text = ""
MseTotal.Text = ""

TKBarang.Text = ""
TNBarang.Text = ""
TSatuan.Text = ""
MseHarga.Text = ""
MseJumlah.Text = ""

Total = 0

End Sub

Sub Detail()
Dim Msql As String

'Mengatur Tampilan record pada Data Grid
Msql = "Select KodeBarang, NamaBarang, HargaBeli, Jumlah, Total" & _
" From tbNotaBeliDetail Where NoNota='" & TNota.Text & "'"

Adodc1.RecordSource = Msql
Adodc1.Refresh

dgDetail.Refresh

End Sub

Read Users' Comments (0)

Koneksi Database Dengan ODBC

Sekarang kita bahas masalah koneksi databasenya, tentu bagi anda yang sudah mengikuti dari awal, bertanya - tanya kok ga bisa jalan sih. he he he (karena ODBCnya belum disetting jelas tidak akan connect). Caranya sebagai Berikut :

1. Kita buka control panel
2. Pilih administrative tools
3. pilih Data Source (ODBC).
kita gunakan system dsn untuk mendukung multi user.

Banyak Aplikasi yang menggunakan OBDC, baik desktop maupun web programming.
Berikut Setting ODBC secara umum.
4. Klik Tombol Add (seperti pada gambar). maka akan muncul form Create New Data Source


5. Akan muncul form berikut :
Pilih Jenis database yang digunakan, MS-Access, MS-SQL, Foxpro, dBase, dll.
Karena kita menggunakan MS-Access maka pilih driver Microsoft Access Driver (*.mdb).
Kemudian Klik Finish. dan akan muncul form ODBC Microsoft Access Setup:

6. Masukan Nama inventori pada text box Data Source Name, kemudian klik tombol select
sehingga muncul form select database :

7. Cari Lokasi database disimpan, kemudian tekan tombol ok jika sudah selesai.
maka akan kembali ke form ODBC Microsoft Access Setup. jika database tersebut
menggunakan User dan Password klik tombol Advanced dan masukan user dan password
databasenya.


Dengan demikian kita telah mensetting ODBC untuk program sederhana yang telah kita buat sebelumnya. Semoga bermanfaat.

Read Users' Comments (0)

Membuat Form Master Stok












Sekarang kita membuat form master stok, masih menggunakan database yang sama.
Kita tambahkan tabel stok, simpan dengan nama tbStok

Berikut Struktur datanya,

Table Name : tbStok



No. Field Name Type Data Length Description Allow Nulls
1 KodeBarang text 10 0
2 NamaBarang text 50 0
3 Satuan text 10 0
4 Jumlah number double 0
Hampir sama dengan form master pelanggan komponen yang kita butuhkan sebagai berikut :

Tambahkan form baru dengan cara klik menu project ==> Add Form dan dari dialog yang muncul pilih Tab New ===> pilih Form

Berikan Nama FrmStok ===> tambahkan SSTAB objek agar terlihat lebih manis, atur properti dan font sesuai dengan keinginan.

Objek Properties Value
Label1 ===> Caption Kode Barang
Label2 ===> Caption Nama Barang
Label3 ===> Caption Satuan
Label4 ===> Caption Jumlah


TextBox => Name Text1
TextBox => Name Text2
TextBox => Name Text3
TextBox => Name MaskedEditBox1

Objek Properties Value
CommandButton Name CmdTambah
Caption Tambah
CommandButton Name CmdSimpan
Caption Simpan
CommandButton Name CmdHapus
Caption Hapus
CommandButton Name CmdUbah
Caption Ubah
CommandButton Name CmdBatal
Caption Batal
CommandButton Name CmdSelesai
Caption Selesai

Atur Form seperti gambar layout diatas.
Kemudian Berikut Scriptnya :

Dim Cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub CmdBatal_Click()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
MaskEdBox1.Enabled = True

Call Kosong

CmdUbah.Enabled = False
CmdHapus.Enabled = False
CmdBatal.Enabled = False
CmdSimpan.Enabled = False

Text1.SetFocus

End Sub

Private Sub CmdHapus_Click()
Dim Msql As String
Dim Konfirmasi As String

If Text1.Text <> "" And Text1.Enabled = False Then
Cnn.BeginTrans
Konfirmasi = MsgBox("Apakah Anda Yakin ingin menghapus Record ??? ", vbYesNo + vbCritical, "Konfirmasi")
If Konfirmasi = vbYes Then

'Menghapus record pada tabel
Msql = "Delete From tbStok" & _
" Where KodeBarang='" & Text1.Text & "'"

Cnn.Execute (Msql)

Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
MaskEdBox1.Enabled = True

CmdTambah.Enabled = False
CmdSimpan.Enabled = False
CmdHapus.Enabled = False
CmdUbah.Enabled = False
CmdBatal.Enabled = False

Call Kosong

Cnn.CommitTrans
End If
End If
End Sub

Private Sub CmdSelesai_Click()

Cnn.Close
Set Cnn = Nothing

Unload Me

Call Menu_Bisa

End Sub

Private Sub CmdSimpan_Click()
Dim Msql As String

If Text1.Text <> "" Then
Cnn.BeginTrans

If Text1.Enabled = True Then

'menambah record pada tabel
Msql = "Insert into tbStok(KodeBarang, NamaBarang, Satuan, Jumlah)" & _
" Values('" & Text1.Text & "','" & Text2.Text & "','" & Text3.Text & "'," & Val(MaskEdBox1.Text) & ")"

'Mengeksekusi perintah SQL
Cnn.Execute (Msql)

Else

'Mengubah record pada tabel
Msql = "Update tbStok set " & _
" NamaBarang ='" & Text2.Text & "'," & _
" Satuan='" & Text3.Text & "'," & _
" Jumlah =" & Val(MaskEdBox1.Text) & "," & _
" Where KodeBarang='" & Text1.Text & "'"

'Mengeksekusi printah SQL
Cnn.Execute (Msql)
End If

Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
MaskEdBox1.Enabled = False

CmdSimpan.Enabled = False
CmdBatal.Enabled = False

CmdTambah.Enabled = True
CmdHapus.Enabled = True
CmdUbah.Enabled = True

Cnn.CommitTrans
End If
End Sub

Private Sub CmdTambah_Click()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
MaskEdBox1.Enabled = True

CmdTambah.Enabled = False
CmdSimpan.Enabled = False
CmdHapus.Enabled = False
CmdUbah.Enabled = False
CmdBatal.Enabled = False

Call Kosong

Text1.SetFocus

End Sub

Private Sub CmdUbah_Click()
Dim Msql As String

If Text1.Text <> "" And Text1.Enabled = False Then
Text2.Enabled = True
Text3.Enabled = True
MaskEdBox1.Enabled = True
Text2.SetFocus

End If

CmdUbah.Enabled = False
CmdHapus.Enabled = False
CmdTambah.Enabled = False

CmdSimpan.Enabled = True
End Sub

Private Sub Form_Activate()
Text1.SetFocus
End Sub

Private Sub Form_Load()

'Membuat Sebuah Koneksi
Set Cnn = New ADODB.Connection

'Membuka Koneksi dengan ODBC Driver Aplikasi
Cnn.Open "inventori"

CmdTambah.Enabled = False
CmdSimpan.Enabled = False
CmdUbah.Enabled = False

CmdHapus.Enabled = False
CmdBatal.Enabled = False

Me.Top = (Main.ScaleHeight - Me.ScaleHeight) / 2
Me.Left = (Main.ScaleWidth - Me.ScaleWidth) / 2

End Sub

Private Sub MaskEdBox1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
MaskEdBox2.SetFocus
Else
Dim StrAngka As String
StrAngka = "0123456789"

If KeyAscii > 26 Then
If InStr(StrAngka, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Private Sub Text1_LostFocus()
Dim Msql As String

If Text1.Text <> "" Then
Cnn.BeginTrans

'Mencari Kode pada Tabel
Msql = "Select * From tbStok " & _
" Where KodeBarang='" & Text1.Text & "'"

Set rs = Cnn.Execute(Msql)

'Jika Kode sudah ada tampilkan
If Not rs.EOF Then

'Menampilkan data dalam tabel ke form
Text2.Text = rs.Fields("NamaBarang")
Text3.Text = rs.Fields("Satuan")
MaskEdBox1.Text = rs.Fields("Jumlah")

Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
MaskEdBox1.Enabled = False

CmdTambah.Enabled = True
CmdHapus.Enabled = True
CmdUbah.Enabled = True

Else
CmdSimpan.Enabled = True
CmdBatal.Enabled = True
End If

rs.Close

Cnn.CommitTrans

End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
Text3.SetFocus
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
MaskEdBox1.SetFocus
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Sub Kosong()

'mengosongkan textbox dan maskededit

Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
MaskEdBox1.Text = ""

End Sub

Read Users' Comments (0)

Membuat Form Master Pemasok / Supplier













Layout diatas adalah bentuk form untuk kita meregistrasikan pemasok / supplier.

Database yang sudah ada kita tambahkan tabelnya dengan tabel pemasok --> kita berikan nama tbPemasok. Struktur tabel yang diperlukan sama dengan tabel pelanggan sebagai berikut

field name tipe data length keterangan
kode text 10 --> diset sebagai primary key
nama text 50
alamat text 50
telp text 15
kota text 15 --> apabila diperlukan dibuat tabel tersendiri

Hampir sama dengan form master pelanggan komponen yang kita butuhkan sebagai berikut :

Tambahkan form baru dengan cara klik menu project ==> Add Form dan dari dialog yang muncul pilih Tab New ===> pilih Form

Berikan Nama FrmPemasok ===> tambahkan SSTAB objek agar terlihat lebih manis, atur properti dan font sesuai dengan keinginan.

Objek Properties Value
Label1 ===> Caption Kode Pemasok
Label2 ===> Caption Nama
Label3 ===> Caption Alamat
Label4 ===> Caption Telepon
Label5 ===> Caption Kota

TextBox => Name Text1
TextBox => Name Text2
TextBox => Name Text3
TextBox => Name Text4
TextBox => Name Text5



Objek Properties Value
CommandButton Name CmdTambah
Caption Tambah
CommandButton Name CmdSimpan
Caption Simpan
CommandButton Name CmdHapus
Caption Hapus
CommandButton Name CmdUbah
Caption Ubah
CommandButton Name CmdBatal
Caption Batal
CommandButton Name CmdSelesai
Caption Selesai

Atur Form seperti gambar layout diatas.
Kemudian Berikut Scriptnya :

Dim Cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub CmdBatal_Click()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True

Call Kosong

CmdUbah.Enabled = False
CmdHapus.Enabled = False
CmdBatal.Enabled = False
CmdSimpan.Enabled = False

Text1.SetFocus

End Sub

Private Sub CmdHapus_Click()
Dim Msql As String
Dim Konfirmasi As String

If Text1.Text <> "" And Text1.Enabled = False Then
Cnn.BeginTrans
Konfirmasi = MsgBox("Mau Hapus Record ??? ", vbYesNo + vbCritical, "Konfirmasi")
If Konfirmasi = vbYes Then

'Menghapus record pada tabel
Msql = "Delete From tbPemasok" & _
" Where Kode='" & Text1.Text & "'"

Cnn.Execute (Msql)

Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True

CmdTambah.Enabled = False
CmdSimpan.Enabled = False
CmdHapus.Enabled = False
CmdUbah.Enabled = False
CmdBatal.Enabled = False

Call Kosong

Cnn.CommitTrans
End If
End If
End Sub

Private Sub CmdSelesai_Click()

Cnn.Close
Set Cnn = Nothing

Unload Me

Call Menu_Bisa

End Sub

Private Sub CmdSimpan_Click()
Dim Msql As String

If Text1.Text <> "" Then
Cnn.BeginTrans

If Text1.Enabled = True Then

'menambah record pada tabel
Msql = "Insert into tbPemasok(Kode, Nama, Alamat, Telp, Kota)" & _
" Values('" & Text1.Text & "','" & Text2.Text & "','" & Text3.Text & "','" & Text4.Text & "','" & Text5.Text & "')"

'Mengeksekusi perintah SQL
Cnn.Execute (Msql)

Else

'Mengubah record pada tabel
Msql = "Update tbPemasok set " & _
" Nama='" & Text2.Text & "'," & _
" Alamat='" & Text3.Text & "'," & _
" Telp='" & Text4.Text & "'," & _
" Kota='" & Text5.Text & "'" & _
" Where Kode='" & Text1.Text & "'"

'Mengeksekusi printah SQL
Cnn.Execute (Msql)
End If

Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False

CmdSimpan.Enabled = False
CmdBatal.Enabled = False

CmdTambah.Enabled = True
CmdHapus.Enabled = True
CmdUbah.Enabled = True

Cnn.CommitTrans
End If
End Sub

Private Sub CmdTambah_Click()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True

CmdTambah.Enabled = False
CmdSimpan.Enabled = False
CmdHapus.Enabled = False
CmdUbah.Enabled = False
CmdBatal.Enabled = False

Call Kosong

Text1.SetFocus

End Sub

Private Sub CmdUbah_Click()
Dim Msql As String

If Text1.Text <> "" And Text1.Enabled = False Then
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Text2.SetFocus
End If

CmdUbah.Enabled = False
CmdHapus.Enabled = False
CmdTambah.Enabled = False

CmdSimpan.Enabled = True
End Sub

Private Sub Form_Activate()
Me.Left = (Main.ScaleHeight - Me.ScaleHeight) / 2
Me.Top = (Main.ScaleWidth - Me.ScaleWidth) / 2

Text1.SetFocus
End Sub

Private Sub Form_Load()

'Membuat Sebuah Koneksi
Set Cnn = New ADODB.Connection

'Membuka Koneksi dengan ODBC Driver Aplikasi
Cnn.Open "inventori"

CmdTambah.Enabled = False
CmdSimpan.Enabled = False
CmdUbah.Enabled = False

CmdHapus.Enabled = False
CmdBatal.Enabled = False



End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
Text2.SetFocus
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Private Sub Text1_LostFocus()
Dim Msql As String

If Text1.Text <> "" Then
Cnn.BeginTrans

'Mencari Kode pada Tabel
Msql = "Select * From tbPemasok " & _
" Where Kode='" & Text1.Text & "'"

Set rs = Cnn.Execute(Msql)

'Jika Kode sudah ada tampilkan
If Not rs.EOF Then

'Menampilkan data dalam tabel ke form
Text2.Text = rs.Fields("Nama")
Text3.Text = rs.Fields("Alamat")
Text4.Text = rs.Fields("Telp")
Text5.Text = rs.Fields("Kota")

Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False

CmdTambah.Enabled = True
CmdHapus.Enabled = True
CmdUbah.Enabled = True

Else
CmdSimpan.Enabled = True
CmdBatal.Enabled = True
End If

rs.Close

Cnn.CommitTrans

End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
Text3.SetFocus
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
Text4.SetFocus
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Private Sub Text4_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
Text5.SetFocus
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Private Sub Text5_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Sub Kosong()

'mengosongkan textbox dan maskededit

Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""

End Sub

Read Users' Comments (0)

Membuat Form Master Pelanggan













Layout diatas adalah bentuk form untuk kita meregistrasikan pelanggan.

Database yang sudah ada kita tambahkan tabelnya dengan tabel pelanggan --> kita berikan nama tbPelanggan. Struktur tabel yang diperlukan sebagai berikut

field name tipe data length keterangan
kode text 10 --> diset sebagai primary key
nama text 50
alamat text 50
telp text 15
kota text 15 --> apabila diperlukan dibuat tabel tersendiri

Hampir sama dengan form master barang, komponen yang kita butuhkan sebagai berikut :

Tambahkan form baru dengan cara klik menu project ==> Add Form dan dari dialog yang muncul pilih Tab New ===> pilih Form

Berikan Nama FrmPelanggan ===> tambahkan SSTAB objek agar terlihat lebih manis, atur properti dan font sesuai dengan keinginan.

Objek Properties Value
Label1 ===> Caption Kode Pelanggan
Label2 ===> Caption Nama
Label3 ===> Caption Alamat
Label4 ===> Caption Telepon
Label5 ===> Caption Kota

TextBox => Name Text1
TextBox => Name Text2
TextBox => Name Text3
TextBox => Name Text4
TextBox => Name Text5

Tambahkan Command Button
Objek Properties Value
CommandButton Name CmdTambah
Caption Tambah
CommandButton Name CmdSimpan
Caption Simpan
CommandButton Name CmdHapus
Caption Hapus
CommandButton Name CmdUbah
Caption Ubah
CommandButton Name CmdBatal
Caption Batal
CommandButton Name CmdSelesai
Caption Selesai

Atur Form seperti gambar layout diatas.
Kemudian Berikut Scriptnya :
Dim Cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub CmdBatal_Click()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True

Call Kosong

CmdUbah.Enabled = False
CmdHapus.Enabled = False
CmdBatal.Enabled = False
CmdSimpan.Enabled = False

Text1.SetFocus

End Sub

Private Sub CmdHapus_Click()
Dim Msql As String
Dim Konfirmasi As String

If Text1.Text <> "" And Text1.Enabled = False Then
Cnn.BeginTrans
Konfirmasi = MsgBox("Mau Hapus Record ??? ", vbYesNo + vbCritical, "Konfirmasi")
If Konfirmasi = vbYes Then

'Menghapus record pada tabel
Msql = "Delete From tbPelanggan" & _
" Where Kode='" & Text1.Text & "'"

Cnn.Execute (Msql)

Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True

CmdTambah.Enabled = False
CmdSimpan.Enabled = False
CmdHapus.Enabled = False
CmdUbah.Enabled = False
CmdBatal.Enabled = False

Call Kosong

Cnn.CommitTrans
End If
End If
End Sub

Private Sub CmdSelesai_Click()

Cnn.Close
Set Cnn = Nothing

Unload Me

Call Menu_Bisa

End Sub

Private Sub CmdSimpan_Click()
Dim Msql As String

If Text1.Text <> "" Then
Cnn.BeginTrans

If Text1.Enabled = True Then

'menambah record pada tabel
Msql = "Insert into tbPelanggan(Kode, Nama, Alamat, Telp, Kota)" & _
" Values('" & Text1.Text & "','" & Text2.Text & "','" & Text3.Text & "','" & Text4.Text & "','" & Text5.Text & "')"

'Mengeksekusi perintah SQL
Cnn.Execute (Msql)

Else

'Mengubah record pada tabel
Msql = "Update tbPelanggan set " & _
" Nama='" & Text2.Text & "'," & _
" Alamat='" & Text3.Text & "'," & _
" Telp='" & Text4.Text & "'," & _
" Kota='" & Text5.Text & "'" & _
" Where Kode='" & Text1.Text & "'"

'Mengeksekusi printah SQL
Cnn.Execute (Msql)
End If

Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False

CmdSimpan.Enabled = False
CmdBatal.Enabled = False

CmdTambah.Enabled = True
CmdHapus.Enabled = True
CmdUbah.Enabled = True

Cnn.CommitTrans
End If
End Sub

Private Sub CmdTambah_Click()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True

CmdTambah.Enabled = False
CmdSimpan.Enabled = False
CmdHapus.Enabled = False
CmdUbah.Enabled = False
CmdBatal.Enabled = False

Call Kosong

Text1.SetFocus

End Sub

Private Sub CmdUbah_Click()
Dim Msql As String

If Text1.Text <> "" And Text1.Enabled = False Then
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Text2.SetFocus
End If

CmdUbah.Enabled = False
CmdHapus.Enabled = False
CmdTambah.Enabled = False

CmdSimpan.Enabled = True
End Sub

Private Sub Form_Activate()
Me.Left = (Main.ScaleHeight - Me.ScaleHeight) / 2
Me.Top = (Main.ScaleWidth - Me.ScaleWidth) / 2

Text1.SetFocus
End Sub

Private Sub Form_Load()

'Membuat Sebuah Koneksi
Set Cnn = New ADODB.Connection

'Membuka Koneksi dengan ODBC Driver Aplikasi
Cnn.Open "inventori"

CmdTambah.Enabled = False
CmdSimpan.Enabled = False
CmdUbah.Enabled = False

CmdHapus.Enabled = False
CmdBatal.Enabled = False



End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
Text2.SetFocus
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Private Sub Text1_LostFocus()
Dim Msql As String

If Text1.Text <> "" Then
Cnn.BeginTrans

'Mencari Kode pada Tabel
Msql = "Select * From tbPelanggan " & _
" Where Kode='" & Text1.Text & "'"

Set rs = Cnn.Execute(Msql)

'Jika Kode sudah ada tampilkan
If Not rs.EOF Then

'Menampilkan data dalam tabel ke form
Text2.Text = rs.Fields("Nama")
Text3.Text = rs.Fields("Alamat")
Text4.Text = rs.Fields("Telp")
Text5.Text = rs.Fields("Kota")

Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False

CmdTambah.Enabled = True
CmdHapus.Enabled = True
CmdUbah.Enabled = True

Else
CmdSimpan.Enabled = True
CmdBatal.Enabled = True
End If

rs.Close

Cnn.CommitTrans

End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
Text3.SetFocus
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
Text4.SetFocus
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Private Sub Text4_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
Text5.SetFocus
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Private Sub Text5_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Sub Kosong()

'mengosongkan textbox dan maskededit

Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""

End Sub

Read Users' Comments (0)

Membuat Form Master Barang


Berikut Layout Form Master Data Barang.

Komponen yang kita butuhkan antara lain
SSTAB, label, textbox, button, dan frame

Penambahan komponen ini dapat dilakukan dengan cara klik--> menu project dan --> pilih component



Pilih dari daftar object yang akan kita gunakan antara lain, sebagai berikut :

1. Crystal Report Control --> berguna untuk membuat report atau laporan.
2. Microsoft ADO Data Control 6.0 (SP4) (oledb).
3. Microsoft DataGrid Control 6.0 (SP5) (oledb)
4. Microsoft Masked Edit Control 6.0 (SP3)
5. Microsoft Tabbed Dialog Control 6.0 (SP5)
6. Microsoft Windows Common Controls-2 6.0 (SP4)

Penulis menggunakan o/s windows xp sp2 dan crystal report 8 --> dan Tentunya microsoft visual studio 2000.

Berikut struktur table barang --> simpan dengan nama tbBarang

Detail Table Inventory Design






Table Name : tbBarang


No. Field Name Type Data Length Description
1 Kode text 10
2 Nama text 40
3 Satuan text 10
4 HargaBeli number double
5 HargaJual number double

Atur form dengan properties sebagai berikut :

Label tidak dibahas (karena biasanya sudah tau untuk penamaan komponen, jadi kita lanjut ke input (isian). Siapkan 3 textbox dan 2 Masked Edit Box

Seperti layout diatas.

berikut script pada form barang, ingat kita menggunakan ADO teknik bukan DAO
jadi jangan lupa tambahkan reference anda dengan cara klik menu --> project --> reference
dan pilih Microsoft ActiveX Data Object 2.0 library.

Dim Cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub CmdBatal_Click()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
MaskEdBox1.Enabled = True
MaskEdBox2.Enabled = True

Call Kosong

CmdUbah.Enabled = False
CmdHapus.Enabled = False
CmdBatal.Enabled = False
CmdSimpan.Enabled = False

Text1.SetFocus

End Sub

Private Sub CmdHapus_Click()
Dim Msql As String
Dim Konfirmasi As String

If Text1.Text <> "" And Text1.Enabled = False Then
Cnn.BeginTrans
Konfirmasi = MsgBox("Mau Hapus Record ??? ", vbYesNo + vbCritical, "Konfirmasi")
If Konfirmasi = vbYes Then

'Menghapus record pada tabel
Msql = "Delete From tbBarang" & _
" Where Kode='" & Text1.Text & "'"

Cnn.Execute (Msql)

Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
MaskEdBox1.Enabled = True
MaskEdBox2.Enabled = True

CmdTambah.Enabled = False
CmdSimpan.Enabled = False
CmdHapus.Enabled = False
CmdUbah.Enabled = False
CmdBatal.Enabled = False

Call Kosong

Cnn.CommitTrans
End If
End If
End Sub

Private Sub CmdSelesai_Click()

Cnn.Close
Set Cnn = Nothing

Unload Me

Call Menu_Bisa

End Sub

Private Sub CmdSimpan_Click()
Dim Msql As String

If Text1.Text <> "" Then
Cnn.BeginTrans

If Text1.Enabled = True Then

'menambah record pada tabel
Msql = "Insert into tbBarang(Kode, Nama, Satuan, HargaBeli, HargaJual)" & _
" Values('" & Text1.Text & "','" & Text2.Text & "','" & Text3.Text & "'," & Val(MaskEdBox1.Text) & "," & MaskEdBox2.Text & ")"

'Mengeksekusi perintah SQL
Cnn.Execute (Msql)

Else

'Mengubah record pada tabel
Msql = "Update tbBarang set " & _
" Nama='" & Text2.Text & "'," & _
" Satuan='" & Text3.Text & "'," & _
" HargaBeli=" & Val(MaskEdBox1.Text) & "," & _
" HargaJual=" & Val(MaskEdBox2.Text) & "" & _
" Where Kode='" & Text1.Text & "'"

'Mengeksekusi printah SQL
Cnn.Execute (Msql)
End If

Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
MaskEdBox1.Enabled = False
MaskEdBox2.Enabled = False

CmdSimpan.Enabled = False
CmdBatal.Enabled = False

CmdTambah.Enabled = True
CmdHapus.Enabled = True
CmdUbah.Enabled = True

Cnn.CommitTrans
End If
End Sub

Private Sub CmdTambah_Click()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
MaskEdBox1.Enabled = True
MaskEdBox2.Enabled = True

CmdTambah.Enabled = False
CmdSimpan.Enabled = False
CmdHapus.Enabled = False
CmdUbah.Enabled = False
CmdBatal.Enabled = False

Call Kosong

Text1.SetFocus

End Sub

Private Sub CmdUbah_Click()
Dim Msql As String

If Text1.Text <> "" And Text1.Enabled = False Then
Text2.Enabled = True
Text3.Enabled = True
MaskEdBox1.Enabled = True
MaskEdBox2.Enabled = True
Text2.SetFocus

End If

CmdUbah.Enabled = False
CmdHapus.Enabled = False
CmdTambah.Enabled = False

CmdSimpan.Enabled = True
End Sub

Private Sub Form_Activate()
Text1.SetFocus
End Sub

Private Sub Form_Load()

'Membuat Sebuah Koneksi
Set Cnn = New ADODB.Connection

'Membuka Koneksi dengan ODBC Driver Aplikasi
Cnn.Open "inventori"

CmdTambah.Enabled = False
CmdSimpan.Enabled = False
CmdUbah.Enabled = False

CmdHapus.Enabled = False
CmdBatal.Enabled = False

Me.Top = (Main.ScaleHeight - Me.ScaleHeight) / 2
Me.Left = (Main.ScaleWidth - Me.ScaleWidth) / 2

End Sub

Private Sub MaskEdBox1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
MaskEdBox2.SetFocus
Else
Dim StrAngka As String
StrAngka = "0123456789"

If KeyAscii > 26 Then
If InStr(StrAngka, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
End If
End Sub

Private Sub MaskEdBox2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
Dim StrAngka As String
StrAngka = "0123456789"

If KeyAscii > 26 Then
If InStr(StrAngka, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Private Sub Text1_LostFocus()
Dim Msql As String

If Text1.Text <> "" Then
Cnn.BeginTrans

'Mencari Kode pada Tabel
Msql = "Select * From tbBarang " & _
" Where Kode='" & Text1.Text & "'"

Set rs = Cnn.Execute(Msql)

'Jika Kode sudah ada tampilkan
If Not rs.EOF Then

'Menampilkan data dalam tabel ke form
Text2.Text = rs.Fields("Nama")
Text3.Text = rs.Fields("Satuan")
MaskEdBox1.Text = rs.Fields("HargaBeli")
MaskEdBox2.Text = rs.Fields("HargaJual")

Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
MaskEdBox1.Enabled = False
MaskEdBox2.Enabled = False

CmdTambah.Enabled = True
CmdHapus.Enabled = True
CmdUbah.Enabled = True

Else
CmdSimpan.Enabled = True
CmdBatal.Enabled = True
End If

rs.Close

Cnn.CommitTrans

End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
Text3.SetFocus
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
MaskEdBox1.SetFocus
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If

End Sub

Sub Kosong()

'mengosongkan textbox dan maskededit

Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
MaskEdBox1.Text = ""
MaskEdBox2.Text = ""

End Sub

Read Users' Comments (1)komentar