• •
Buatlah database baru dan beri nama penjualan Buat beberapa tabel berikut: 1. Barang Field Tipe Data Size Kodebrg Text 12 Namabrg Text 30 Hargabl Currency Hargajl
Currency
-
Stok
Number
Integer
Keterangan Primary key Input mask 99,999,999,99 Input mask 99,999,999,99 -
2. User
Field userid namauser password akses
Tipe Data Text Text Text Text
Size 12 30 8 10
Keterangan Primary key -
Tipe Data Text Date/time text
Size 12 Long date 12
Keterangan Primary key -
Field Nofak Qty bayar
Tipe Data Text number Currency
Size
Keterangan
12 integer -
kodebrg
text
12
3. Faktur
Field Nofak tglfak userid 4. Detail_faktur
Input mask 99,999,999,99
5. Sementara
Field Kodebrg Namabrg Hargajl
Tipe Data Text Text Currency
Size 12 30 -
Qty bayar
Number Currency
integer -
Keterangan Input mask 99,999,999,99 Input mask 99,999,999,99
•
•
Tambahkan Komponen berikut: yang akan ditambahkan -
Microsoft Datagrid control 6.0 (OLEDB)
-
Microsoft tabbed dialog control 6.0
Tambahkan Library berikut: ditambahkan -
•
tekan Ctrl + T di keyboard
dari menu project
Microsoft Activex Data Object 2.8 Library
Buat form baru dan design seperti berikut:
Referneces
checklist componen
checklist library yang
Listing Form Barang •
Di ketik di modul nama modul1
dari menu project
add module
open dan simpan dengan
Public conn As New ADODB.Connection Public RsBarang As New ADODB.Recordset Public Sub koneksi() Set conn = New ADODB.Connection conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\penjualan.mdb" Set RsBarang = New ADODB.Recordset RsBarang.CursorLocation = adUseClient RsBarang.Open "select * from barang", conn End Sub Sub kuncitext(f As Form, b As Boolean) Dim X As Control For Each X In f If TypeOf X Is TextBox Then X.Enabled = b Next End Sub Sub bukatext(f As Form, b As Boolean) Dim X As Control For Each X In f If TypeOf X Is TextBox Then X.Enabled = b Next End Sub Sub bersih(f As Form, Y As String) Dim X As Control For Each X In f If TypeOf X Is TextBox Then X = Y Next End Sub •
Untuk mematikan tekbox
Untuk koneksi ke database
Untuk koneksi ke database
Diketik di tempat listing form biasa Dim isi As Boolean ‘ini untuk mengatur tombol mana yg aktif dan tombol mana yang tidak aktif Public Sub aturtombol(tambah, simpan, batal, hapus, ubah As Boolean) cmdtambah.Enabled = tambah cmdsimpan.Enabled = simpan cmdbatal.Enabled = batal cmdhapus.Enabled = hapus cmdubah.Enabled = ubah
Untuk koneksi ke database
End Sub ‘ini untuk membuat nomor otomatis dengan berdasarkan tahun dan tanggal contoh 201203001 Sub nomor() RsBarang.Close RsBarang.Open "select*from barang order by kodebrg desc" With RsBarang If .BOF And .EOF Then kodebrg = "BR" + Format(Date, "yyyy") + Format(Date, "mm") + "001" Else .MoveFirst kodebrg = "BR" + Format(Date, "yyyy") + Format(Date, "mm") + Right(Str(Val(Right(RsBarang.Fields("kodebrg"), 3)) + 1001), 3) End If End With End Sub Sub tampil() kodebrg = RsBarang.Fields("kodebrg") namabrg = RsBarang.Fields("namabrg") hargabl = RsBarang.Fields("hargabl") hargajl = RsBarang.Fields("hargajl") stok = RsBarang.Fields("stok") End Sub
Private Sub back_Click() RsBarang.MovePrevious If RsBarang.BOF Then MsgBox "Sudah di awal record", vbInformation, "INFO" RsBarang.MoveFirst End If Call tampil Call aturtombol(1, 0, 0, 1, 1) End Sub Private Sub cmdbatal_Click() Call Form_Activate End Sub Private Sub cmdhapus_Click() a = MsgBox("Yakin Data ini akan di hapus?", vbQuestion + vbYesNo, "KONFIRMASI") If a = vbYes Then RsBarang.Close RsBarang.Open "delete from barang where kodebrg=' " & kodebrg & " ' " MsgBox "Data Telah Terhapus", vbInformation, "INFO" Call Form_Load Call Form_Activate End If
End Sub Private Sub cmdkeluar_Click() a = MsgBox("Terima Kasih", vbInformation + vbOKOnly, "Informasi") If a = vbOK Then Unload Me End If End Sub Private Sub cmdsearch_Click() RsBarang.Close RsBarang.Open "select * from barang where kodebrg=' " & tkodebrg & " ' " Set DGbarang.DataSource = RsBarang End Sub Private Sub cmdsimpan_Click() If kodebrg = " " Or namabrg = " " Or hargabl = " " Or hargajl = " " Or stok = " " Then MsgBox "Data Harus Diisi", vbInformation + vbOKOnly, "INFO" namabrg.SetFocus Exit Sub End If If isi = True Then RsBarang.Close RsBarang.Open "insert into barang values(' " & kodebrg & " ',' " & namabrg & " ',' " & hargabl & " ',' " & hargajl & " ',' " & stok & " ')" MsgBox "Data Tersimpan", vbInformation + vbOKOnly, "INFO" Call Form_Load Call Form_Activate Else RsBarang.Close RsBarang.Open "update barang set namabrg=' " & namabrg & " ',hargabl=' " & hargabl & " ',hargajl=' " & hargajl & " ',stok=' " & stok & " ' where kodebrg=' " & kodebrg & " ' " MsgBox "Data Berhasil diUpadate", vbInformation + vbOKOnly, "INFO" Call Form_Load Call Form_Activate End If End Sub Private Sub cmdtambah_Click() isi = True Call bukatext(Me, True) Call bersih(Me, "") nomor kodebrg.Enabled = 0 namabrg.SetFocus Call aturtombol(0, 1, 1, 0, 0) End Sub Private Sub cmdubah_Click() isi = False
Call bukatext(Me, 1) kodebrg.Enabled = 0 Call aturtombol(0, 1, 1, 0, 0) End Sub Private Sub DGbarang_Click() With RsBarang kodebrg = .Fields("kodebrg") namabrg = .Fields("namabrg") hargabl = .Fields("hargabl") hargajl = .Fields("hargajl") stok = .Fields("stok") Call aturtombol(1, 0, 0, 1, 1) End With End Sub Private Sub first_Click() RsBarang.MoveFirst Call tampil MsgBox "Sudah di awal record", vbInformation, "INFO" Call aturtombol(1, 0, 0, 1, 1) End Sub Private Sub Form_Activate() Call aturtombol(1, 0, 0, 0, 0) Call kuncitext(Me, False) tkodebrg.Enabled = 1 tnamabrg.Enabled = 1 Call bersih(Me, "") End Sub Private Sub Form_Load() Call koneksi Set DGbarang.DataSource = RsBarang End Sub Private Sub namabrg_KeyPress(KeyAscii As Integer) KeyAscii = Asc(UCase(Chr(KeyAscii))) End Sub Private Sub last_Click() RsBarang.MoveLast Call tampil MsgBox "Sudah di akhir record", vbInformation, "INFO" Call aturtombol(1, 0, 0, 1, 1) End Sub Private Sub next_Click() RsBarang.MoveNext If RsBarang.EOF Then MsgBox "Sudah di akhir record", vbInformation, "INFO"
RsBarang.MoveLast End If Call tampil Call aturtombol(1, 0, 0, 1, 1) End Sub Private Sub tkodebrg_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then RsBarang.Close RsBarang.Open "select * from barang where kodebrg=' " & tkodebrg & " ' " Set DGbarang.DataSource = RsBarang End If End Sub Private Sub tnamabrg_Change() RsBarang.Close RsBarang.Open "select * from barang where namabrg like' %" & tnamabrg & "% ' " Set DGbarang.DataSource = RsBarang End Sub