1. Desain Database dan Tabel seperti berikut :
  2. image image
  3. Buat digram seperti :
  4. image
  5. Buat view seperti :
  6. image
  7. Desain Form di VB 6.0
  8. image
  9. Hubungkan tabel Barang dengan ADODC1, Tabel Transaksi dengan ADODC2 dan View dengan ADODC3
  10. Ketikkan Kode Program dibawah ini
Private Sub Command1_Click()
Text3.Text = 0
Adodc2.Refresh
Adodc2.Recordset.AddNew
Adodc2.Recordset.Fields(0) = Text7.Text
Adodc2.Recordset.Fields(1) = Text1.Text
Adodc2.Recordset.Fields(2) = Text2.Text
Adodc2.Recordset.Fields(3) = Date
Adodc2.Recordset.Update
Adodc3.RecordSource = "select * from view1 where kode_transaksi=’" & Text7.Text & "’"
Adodc3.Refresh
For X = 1 To Adodc3.Recordset.RecordCount
Text3.Text = Val(Text3.Text) + Adodc3.Recordset.Fields("total")
Adodc3.Recordset.MoveNext
Next X

Text2.Text = 1
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
‘Menblok isi text1
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End Sub

Private Sub Command2_Click()
Adodc2.Refresh
Text7.Text = Format(Date, "ddmmyy") & "TX" & Adodc2.Recordset.RecordCount + 1
Adodc3.RecordSource = "select * from view1 where kode_transaksi=’gfergrereyreyreuyrethuyreuy’"
Adodc3.Refresh
End Sub

Private Sub Form_Load()
Text1.Text = ""
Text2.Text = 1
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text8.Text = ""
Text9.Text = ""
Adodc2.Refresh
Text7.Text = Format(Date, "ddmmyy") & "TX" & Adodc2.Recordset.RecordCount + 1
Adodc3.RecordSource = "select * from view1 where kode_transaksi=’gfergrereyreyreuyrethuyreuy’"
Adodc3.Refresh
Label1.Caption = Format(Date, "dddd, dd mmmm yyyy")
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Dim CARI As String
CARI = "KODE_BRG=’" & Text1.Text & "’"
Adodc1.Refresh
Adodc1.Recordset.Find CARI
If Adodc1.Recordset.EOF Then
   MsgBox "data tdk ada"
Else
   Text4.Text = Adodc1.Recordset.Fields(1)
   Text5.Text = Adodc1.Recordset.Fields(2)
   Text2.SetFocus
   Text2.SelStart = 0
   Text2.SelLength = Len(Text2)
End If
End If
End Sub

Private Sub Text2_Change()
   Text6.Text = Val(Text2.Text) * Val(Text5.Text)

End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
   Text6.Text = Val(Text2.Text) * Val(Text5.Text)
   Command1.SetFocus
End If
End Sub

Private Sub Text8_Change()
Text9.Text = Val(Text8.Text) – Val(Text3.Text)
End Sub

Hasilnya :



 image
Source : http://kamaluddin.netau.net/