You are on page 1of 6

Rancangan Program Penjualan dengan VB

Sruktur Database
Database : penjualan.mdb
Tabel:
1. Barang
Name
Type
Size
Keteranga
KdBaran
Text
10
Primary
g
Key
NmBaran
Text
20
g
Satuan
Text
10
Harga
Curren
cy
Stok
Numbe
r
2. Customer
Name
IdCust
NmCust
Alamat
Telp
3. Transaksi
Name
NoTrans
TglJual
Total
IdCust
4. Detail
Name
NoTrans
Qty
SubTotal
KdBaran
g
5. Sementara
Name
KdBaran

Type
Text

Size
10

Text
Text
Text

20
30
15

Type
Text

Size
10

Date/Ti
me
Currenc
y
Text

10

Type
Text
Number
Currenc
y
Text

Size
10

Type
Text

Size
10

Keteranga
Primary
Key

Keteranga
Primary
Key

Keteranga

10

Keteranga

g
NmBaran
g
Harga
Qty
Subtotal

Text

20

Currenc
y
Number
Currenc
y

DataCombo

DataCombo

DataGrid

Untuk membuat DataCombo tambahkan dulu component: Microsoft DataList Control


6.0

Objec
Adodc1
Adodc2
Adodc3
Adodc4
Adodc5

DataCombo1

DataCombo2

DataGrid1

Properties
Name
ConnectionString
RecordSource
Name
ConnectionString
RecordSource
Name
ConnectionString
RecordSource
Name
ConnectionString
RecordSource
Name
ConnectionString
RecordSource
Name
DataSource
RowSource
ListField
Name
DataSource
RowSource
ListField
Name
DataSource

Value
AdoBrg
Penjualan
Barang
AdoCus
Penjualan
Customer
AdoTrans
Penjualan
Transaksi
AdoDet
Penjualan
Detail
AdoSem
Penjualan
Sementara
cbcus
AdoCus
AdoCus
IdCust
cbcbrg
AdoBrg
AdoBrg
KdBarang
DataGrid1
AdoSem

Coding:
Buatlah sub bersih,mati dan hidup di Modul
Private Sub Form_Load()
bersih Me
mati Me
bInput.Enabled = True
bSave.Enabled = False
bCancel.Enabled = False
bExit.Enabled = True
End Sub
Sub nomor()
Dim no As Integer
AdoTrans.Refresh
With AdoTrans.Recordset
If .RecordCount <= 0 Then

txtno.Text = "NT" + Format(Date,


"YYMM") + "001"
Else
.MoveLast
no = Val(Right(!NoTrans, 3)) + 1
txtno.Text = "NT" + Format(Date,
"YYMM") + Format(no, "000")
End If
End With
End Sub
Private Sub bInput_Click()
nomor
cbcus.Enabled = True

bCancel.Enabled = True
bInput.Enabled = False
End Sub
Private Sub cbcus_Click(Area As
Integer)
AdoCus.Refresh
With AdoCus.Recordset
.Find "IdCus='" & cbcus.Text & "'"
If Not .EOF Then
txtnc.Text = !NmCus
txtalamat.Text = !Alamat
txttlp.Text = !Telp
End If
End With
cbbrg.Enabled = True
End Sub
Private Sub cbbrg_Change()
AdoBrg.Refresh
With AdoBrg.Recordset
.Find "KdBarang='" & cbbrg.Text &
"'"
If Not .EOF Then
txtnb.Text = !NmBarang
txtharga.Text = !Harga
End If
txtjb.Enabled = True
txtjb.SetFocus
End With
End Sub
Private Sub
txtjb_KeyPress(KeyAscii As
Integer)
If KeyAscii = 13 Then
'cek stok
AdoBrg.Refresh
AdoBrg.Recordset.Find "KdBarang='" &
cbbrg.Text & "'"
If Val(txtjb.Text) > AdoBrg.Recordset!
Stok Then

MsgBox "Stok tidak mencukupi",


vbInformation + vbOKOnly, "Info"
Else
txttot.Text = Val(txtharga.Text) *
Val(txtjb.Text) '->subtotal
txttobay.Text = Val(txttobay.Text) +
Val(txttot.Text)
'update stok / mengurangi di tabel
barang
x = AdoBrg.Recordset!Stok Val(txtjb.Text)
AdoBrg.Recordset!Stok = x
AdoBrg.Recordset.Update
'simpan ke tabel sementara
AdoSem.Refresh
AdoSem.Recordset.AddNew
AdoSem.Recordset!KdBarang =
cbbrg.Text
AdoSem.Recordset!NmBarang =
txtnb.Text
AdoSem.Recordset!Harga =
txtharga.Text
AdoSem.Recordset!Qty = txtjb.Text
AdoSem.Recordset!SubTotal =
txttot.Text
AdoSem.Recordset.Update
a = MsgBox("Beli Lagi?",
vbQuestion + vbYesNo, "Tanya")
If a = vbYes Then
cbbrg.Text = ""
txtnb.Text = ""
txtharga.Text = ""
txtjb.Text = ""
txttot.Text = ""
cbbrg.SetFocus
Else
bSave.Enabled = True
txtubay.Enabled = True
txtubay.SetFocus
End If
End If

End If
End Sub
Private Sub txtubay_Change()
txtukem.Text = Val(txtubay.Text) Val(txttobay.Text)
End Sub
Private Sub bSave_Click()
'simpan ke tabel transaksi
AdoTrans.Refresh
AdoTrans.Recordset.AddNew
AdoTrans.Recordset!NoTrans =
txtno.Text
AdoTrans.Recordset!TglJual =
txttgl.Text
AdoTrans.Recordset!Total =
txttobay.Text
AdoTrans.Recordset!IdCus =
cbcus.Text
AdoTrans.Recordset.Update
'simpan ke tabel detail
AdoSem.Refresh
AdoSem.Recordset.MoveFirst
While Not AdoSem.Recordset.EOF
AdoDet.Refresh
With AdoDet.Recordset
.AddNew
!NoTrans = txtno.Text

!Qty = AdoSem.Recordset!Qty
!SubTotal = AdoSem.Recordset!
SubTotal
!KdBarang = AdoSem.Recordset!
KdBarang
.Update
End With
'menghapus record tabel
sementara per baris
AdoSem.Recordset.Delete
AdoSem.Recordset.MoveNext
Wend
Form_Load
End Sub
Private Sub bCancel_Click()
Form_Load
End Sub
Private Sub bExit_Click()
a = MsgBox("Are You Sure Want to
Exit?", vbQuestion + vbYesNo,
"Confirm")
If a = vbYes Then
Unload Me
End If
End Sub

You might also like