VERSION 5.00
Begin VB.Form FormBeli 
   BackColor       =   &H00C0E0FF&
   Caption         =   "Form Pembelian"
   ClientHeight    =   5340
   ClientLeft      =   60
   ClientTop       =   750
   ClientWidth     =   6990
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   5340
   ScaleWidth      =   6990
   WindowState     =   2  'Maximized
   Begin VB.TextBox txtTanggalBon 
      Appearance      =   0  'Flat
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   2280
      TabIndex        =   16
      Top             =   600
      Width           =   1575
   End
   Begin VB.ComboBox cboBarang 
      Appearance      =   0  'Flat
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   2280
      TabIndex        =   15
      Top             =   1320
      Width           =   2295
   End
   Begin VB.ComboBox cboPelanggan 
      Appearance      =   0  'Flat
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   2280
      TabIndex        =   14
      Top             =   960
      Width           =   2295
   End
   Begin VB.TextBox txtJumlah 
      Appearance      =   0  'Flat
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   405
      Left            =   2280
      TabIndex        =   12
      Top             =   2760
      Width           =   3135
   End
   Begin VB.TextBox txtBanyaknyaBarang 
      Appearance      =   0  'Flat
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   2280
      TabIndex        =   10
      Top             =   2400
      Width           =   975
   End
   Begin VB.TextBox txtHargaBarang 
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   2280
      TabIndex        =   8
      Top             =   2040
      Width           =   2295
   End
   Begin VB.TextBox txtNamaBarang 
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   2280
      TabIndex        =   6
      Top             =   1680
      Width           =   3855
   End
   Begin VB.TextBox txtNoBon 
      Appearance      =   0  'Flat
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   2280
      TabIndex        =   1
      Top             =   240
      Width           =   1575
   End
   Begin VB.CommandButton cmdFirst 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0FFFF&
      Caption         =   "|<"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   1440
      Style           =   1  'Graphical
      TabIndex        =   17
      Top             =   3720
      Width           =   855
   End
   Begin VB.CommandButton cmdNext 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0FFFF&
      Caption         =   ">"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   3360
      Style           =   1  'Graphical
      TabIndex        =   18
      Top             =   3720
      Width           =   855
   End
   Begin VB.CommandButton cmdPrevious 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0FFFF&
      Caption         =   "<"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   2400
      Style           =   1  'Graphical
      TabIndex        =   19
      Top             =   3720
      Width           =   855
   End
   Begin VB.CommandButton cmdLast 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0FFFF&
      Caption         =   ">|"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   4320
      Style           =   1  'Graphical
      TabIndex        =   20
      Top             =   3720
      Width           =   855
   End
   Begin VB.CommandButton cmdTambah 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0FFC0&
      Caption         =   "&Tambah"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   480
      Style           =   1  'Graphical
      TabIndex        =   21
      Top             =   4560
      Width           =   1335
   End
   Begin VB.CommandButton cmdTutup 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0FFC0&
      Caption         =   "T&utup"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   4800
      Style           =   1  'Graphical
      TabIndex        =   22
      Top             =   4560
      Width           =   1335
   End
   Begin VB.CommandButton cmdHapus 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0FFC0&
      Caption         =   "&Hapus"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   3360
      Style           =   1  'Graphical
      TabIndex        =   23
      Top             =   4560
      Width           =   1335
   End
   Begin VB.CommandButton cmdSimpan 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0FFC0&
      Caption         =   "&Simpan"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   1920
      Style           =   1  'Graphical
      TabIndex        =   24
      Top             =   4560
      Width           =   1335
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00C0E0FF&
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   1080
      TabIndex        =   25
      Top             =   3480
      Width           =   4455
   End
   Begin VB.Label Label9 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0E0FF&
      Caption         =   "dd-mm-yyyy"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000008&
      Height          =   255
      Left            =   4080
      TabIndex        =   13
      Top             =   600
      Width           =   1455
   End
   Begin VB.Label Label8 
      BackColor       =   &H00C0E0FF&
      Caption         =   "Jumlah"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   720
      TabIndex        =   11
      Top             =   2760
      Width           =   1215
   End
   Begin VB.Label Label7 
      BackColor       =   &H00C0E0FF&
      Caption         =   "Banyak"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   720
      TabIndex        =   9
      Top             =   2400
      Width           =   1215
   End
   Begin VB.Label Label6 
      BackColor       =   &H00C0E0FF&
      Caption         =   "Harga Satuan"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   720
      TabIndex        =   7
      Top             =   2040
      Width           =   1215
   End
   Begin VB.Label Label5 
      BackColor       =   &H00C0E0FF&
      Caption         =   "Nama Barang"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   720
      TabIndex        =   5
      Top             =   1680
      Width           =   1215
   End
   Begin VB.Label Label4 
      BackColor       =   &H00C0E0FF&
      Caption         =   "Kode Barang"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   720
      TabIndex        =   4
      Top             =   1320
      Width           =   1215
   End
   Begin VB.Label Label3 
      BackColor       =   &H00C0E0FF&
      Caption         =   "Kode Pelanggan"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   720
      TabIndex        =   3
      Top             =   960
      Width           =   1455
   End
   Begin VB.Label Label2 
      BackColor       =   &H00C0E0FF&
      Caption         =   "Tanggal Bon"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   720
      TabIndex        =   2
      Top             =   600
      Width           =   1215
   End
   Begin VB.Label Label1 
      BackColor       =   &H00C0E0FF&
      Caption         =   "No Bon"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   720
      TabIndex        =   0
      Top             =   240
      Width           =   1215
   End
   Begin VB.Menu keluar 
      Caption         =   "Keluar"
   End
End
Attribute VB_Name = "FormBeli"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim conAVB As ADODB.Connection
Dim rsPelanggan As ADODB.Recordset
Dim rsPembelian As ADODB.Recordset
Dim rsBarang As ADODB.Recordset
Dim Nilai As Integer

Private Sub cboPelanggan_Click()
   cboBarang.SetFocus
End Sub

Private Sub cmdTambah_Click()
  On Error GoTo HandleError
  If cmdTambah.Caption = "&Tambah" Then
      txtNoBon.Locked = False
      txtNoBon.SetFocus
      NonAktifkanKontrol
      cmdTambah.Caption = "&Batal"
      cmdSimpan.Enabled = True
      BersihText
  Else
      rsPembelian.CancelUpdate
      AktifkanTombol
      cmdTambah.Caption = "&Tambah"
      cmdSimpan.Enabled = False
      rsPembelian.MoveLast
      BersihText
  End If

cmdTambah_Click_Exit:
  Exit Sub

HandleError:
  MsgBox "Proses tidak bisa dikerjakan.", vbInformation, "Perhatian"
  On Error GoTo 0
End Sub

Private Sub cmdHapus_Click()
  On Error GoTo HandleError
  cboBarang_Click
  Dim NILAi2 As Integer
  NILAi2 = Nilai - Val(txtBanyaknyaBarang.Text)
  With rsPembelian
    .Delete
    .Requery
    If .EOF Then
        MsgBox "Data Kosong.", vbInformation, "Perhatian"
        NonAktifkanKontrol
    End If
  End With
  BersihText
  With rsBarang
    ![Jumlah Barang] = NILAi2
    .Update
    .Requery
  End With

cmdHapus_Click_Exit:
  Exit Sub

HandleError:
  MsgBox "Data tidak dapat diproses.", vbInformation, "Perhatian"
  On Error GoTo 0
End Sub


Private Sub cmdSimpan_Click()
  cboBarang_Click
  Dim NILAI1 As Integer
  NILAI1 = Nilai + Val(txtBanyaknyaBarang.Text)
  With rsBarang
    ![Jumlah Barang] = NILAI1
    .Update
    .Requery
  End With
  With rsPembelian
     .AddNew
     ![No Bon] = txtNoBon.Text
     ![Tanggal Bon] = txtTanggalBon.Text
     ![Kode Pelanggan] = cboPelanggan.Text
     ![Kode Barang] = cboBarang.Text
     ![Nama Barang] = txtNamaBarang.Text
     ![Harga Satuan] = txtHargaBarang.Text
     ![Banyak] = txtBanyaknyaBarang.Text
     ![Jumlah Uang] = txtJumlah.Text
     .Update
     .Requery
  End With
  txtNoBon.Locked = True
  AktifkanTombol
  cmdSimpan.Enabled = False
  cmdTambah.Caption = "&Tambah"
  
cmdSimpan_Click_Exit:
  Exit Sub

HandleErrors:
  Dim strMessage As String
  Dim errDBError As ADODB.Error
  For Each errDBError In conAVB.Errors
    strMessage = strMessage & errDBError.Description & vbCrLf
  Next
  MsgBox strMessage, vbExclamation, "Data Kembar"
  On Error GoTo 0
End Sub

Private Sub NonAktifkanKontrol()
  cmdNext.Enabled = False
  cmdPrevious.Enabled = False
  cmdFirst.Enabled = False
  cmdLast.Enabled = False
  cmdHapus.Enabled = False
End Sub

Private Sub AktifkanTombol()
  cmdNext.Enabled = True
  cmdPrevious.Enabled = True
  cmdFirst.Enabled = True
  cmdLast.Enabled = True
 cmdHapus.Enabled = True
End Sub

Private Sub cmdFirst_Click()
  On Error Resume Next
  rsPembelian.MoveFirst
  TampilkanData
End Sub

Private Sub cmdLast_Click()
  On Error Resume Next
  rsPembelian.MoveLast
  TampilkanData
End Sub

Private Sub cmdNext_Click()
  On Error Resume Next
  With rsPembelian
    .MoveNext
    If .EOF Then
       .MoveLast
    End If
    TampilkanData
  End With
End Sub

Private Sub cmdPrevious_Click()
  On Error Resume Next
  With rsPembelian
    .MovePrevious
    If .BOF Then
       .MoveFirst
    End If
    TampilkanData
  End With
End Sub

Private Sub cmdTutup_Click()
  Unload Me
End Sub

Private Sub cboBarang_Click()
  Dim strSearch As String
  Dim vntBookMark As Variant
  strSearch = "[Kode Barang] =  '" & cboBarang & "'"
  With rsBarang
    .MoveFirst
    .Find strSearch
    txtHargaBarang.Text = ![Harga Barang]
    txtNamaBarang.Text = ![Nama Barang]
    Nilai = ![Jumlah Barang]
  End With
  txtBanyaknyaBarang.SetFocus
End Sub

Private Sub Form_Load()
  Dim strSQL As String
  Set conAVB = New ADODB.Connection
    conAVB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Persist Security info=False;Data source =" & App.Path & _
    "\AVB.mdb;mode = readwrite"
    conAVB.Open
  Set rsBarang = New ADODB.Recordset
  strSQL = "SELECT * FROM Barang"
    rsBarang.Open strSQL, conAVB, adOpenDynamic, adLockOptimistic, adCmdText
  Set rsPelanggan = New ADODB.Recordset
  strSQL = "SELECT [Kode Pelanggan] FROM Pelanggan"
    rsPelanggan.Open strSQL, conAVB, adOpenDynamic, adLockOptimistic, adCmdText
  Set rsPembelian = New ADODB.Recordset
  strSQL = "SELECT * FROM TabelBeli"
    rsPembelian.Open strSQL, conAVB, adOpenDynamic, adLockOptimistic, adCmdText
    
  With rsPelanggan
    While Not .EOF
      If Not .BOF Then
        cboPelanggan.AddItem ![Kode Pelanggan]
        .MoveNext
      End If
    Wend
  End With
  
 With rsBarang
    While Not .EOF
      If Not .BOF Then
        cboBarang.AddItem ![Kode Barang]
        .MoveNext
      End If
    Wend
  End With
End Sub

Private Sub keluar_Click()
  Unload Me
End Sub

Private Sub txtBanyaknyaBarang_KeyPress(KeyAscii As Integer)
  If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then
    Beep
    KeyAscii = 0
  End If
End Sub

Private Sub txtHargaBarang_Change()
  Dim Jumlah As Single
  Jumlah = Val(txtHargaBarang.Text) * Val(txtBanyaknyaBarang.Text)
  On Error GoTo Salah
  txtJumlah.Text = Format(Jumlah, "Rp ###,###,###") & ",-"
  Exit Sub
Salah:
End Sub

Private Sub txtBanyaknyaBarang_Change()
  Dim Jumlah As Single
  Jumlah = Val(txtHargaBarang.Text) * Val(txtBanyaknyaBarang.Text)
  On Error GoTo Salah
  txtJumlah.Text = Format(Jumlah, "Rp ###,###,###") & ",-"
  On Error GoTo 0
  Exit Sub
Salah:
End Sub

Private Sub txtHargaBarang_KeyPress(KeyAscii As Integer)
  If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then
    Beep
    KeyAscii = 0
  End If
End Sub


Private Sub txtNoBon_KeyPress(KeyAscii As Integer)
   If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii <= Asc("-") Or KeyAscii = vbKeyBack) Then
     Beep
     KeyAscii = 0
   End If
   If KeyAscii = 13 Then
     txtTanggalBon.SetFocus
   End If
End Sub

Private Sub txtTanggalBon_KeyPress(KeyAscii As Integer)
   If KeyAscii = 13 Then
     cboPelanggan.SetFocus
   End If
End Sub

Private Sub TampilkanData()
  With rsPembelian
    txtNoBon.Text = ![No Bon]
    txtTanggalBon.Text = ![Tanggal Bon]
    cboPelanggan.Text = ![Kode Pelanggan]
    cboBarang.Text = ![Kode Barang]
    txtNamaBarang.Text = ![Nama Barang]
    txtHargaBarang.Text = ![Harga Satuan]
    txtBanyaknyaBarang.Text = ![Banyak]
    txtJumlah.Text = ![Jumlah]
  End With
End Sub

Private Sub BersihText()
  With rsPembelian
    txtNoBon.Text = ""
    txtTanggalBon.Text = ""
    cboPelanggan.Text = ""
    cboBarang.Text = ""
    txtNamaBarang.Text = ""
    txtHargaBarang.Text = ""
    txtBanyaknyaBarang.Text = ""
    txtJumlah.Text = ""
  End With
End Sub

