Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Total As Double
Private Sub cmdKeluar_Click()
Unload Me
Call Menu_Bisa
End Sub
Private Sub Form_Load()
Dim Koneksi As String
'Driver ODBC Connection String
Koneksi = "FILE NAME=C:\Program Files\" & _
"Common Files\ODBC\Data Sources\dbinventori.dsn"
cnn.Open Koneksi, "simon", "1234"
Call Detail
cmdtambah.Enabled = False
cmdsimpan.Enabled = False
cmdhapus.Enabled = False
cmdbatal.Enabled = False
Total = 0
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
End If
End Sub
Private Sub txtKode_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub
Private Sub mseJumlah_LostFocus()
Dim TotalBrg As Double
If txtkodebarang.Text <> "" Then
cnn.BeginTrans
TotalBrg = Val(mseharga.Text) * Val(msejumlah.Text)
Total = Total + TotalBrg
msql = "Insert into tbNotaBeliDetail(NoNota,KodeBarang," & _
" NamaBarang,HargaBeli,Satuan,Jumlah,Total)" & _
" Values('" & txtnota.Text & "','" & txtkodebarang.Text & "', " & _
" '" & txtnamabarang.Text & "'," & Val(mseharga.Text) & "," & _
" '" & txtsatuan.Text & "'," & Val(msejumlah.Text) & "," & _
" " & Val(TotalBrg) & ")"
cnn.Execute (msql)
cnn.CommitTrans
Call Detail
txtkodebarang.SetFocus
txtkodebarang.Text = ""
txtnamabarang.Text = ""
txtsatuan.Text = ""
mseharga.Text = ""
msejumlah.Text = ""
msesubtotal.Text = Total
msetotal.Text = Total
End If
End Sub
Private Sub msePotongan_LostFocus()
msetotal.Text = Total - Val(msepotongan.Text)
End Sub
Private Sub txtKodeBarang_LostFocus()
Dim msql As String
If txtkodebarang.Text <> "" Then
msql = "select * from tbBarang " & _
" where kode='" & txtkodebarang.Text & "'"
Set rs = cnn.Execute(msql)
If Not rs.EOF Then
txtnamabarang.Text = rs.Fields("Nama")
mseharga.Text = rs.Fields("HargaBeli")
txtsatuan.Text = rs.Fields("Satuan")
End If
rs.Close
End If
End Sub
Private Sub txtKodePemasok_LostFocus()
Dim msql As String
If txtkodepemasok.Text <> "" Then
msql = "select * from tbpemasok " & _
" where kode='" & txtkodepemasok.Text & "'"
Set rs = cnn.Execute(msql)
If Not rs.EOF Then
txtnamapemasok.Text = rs.Fields("Nama")
End If
rs.Close
End If
End Sub
Private Sub txtNota_LostFocus()
Dim msql As String
If txtnota.Text <> "" Then
cnn.BeginTrans
msql = "select * from tbNotaBeli " & _
" where NoNota='" & txtnota.Text & "'"
Set rs = cnn.Execute(msql)
If Not rs.EOF Then
dptanggal.Value = rs.Fields("Tanggal")
txtkodepemasok.Text = rs.Fields("KodePemasok")
txtnamapemasok.Text = rs.Fields("NamaPemasok")
txtketerangan.Text = rs.Fields("Keterangan")
msesubtotal.Text = rs.Fields("SubTotal")
msepotongan.Text = rs.Fields("Potongan")
msetotal.Text = rs.Fields("TotalAkhir")
Call Detail
txtnota.Enabled = False
txtkodepemasok.Enabled = False
txtnamapemasok.Enabled = False
txtketerangan.Enabled = False
msesubtotal.Enabled = False
msepotongan.Enabled = False
msetotal.Enabled = False
txtkodebarang.Enabled = False
txtnamabarang.Enabled = False
txtsatuan.Enabled = False
mseharga.Enabled = False
msejumlah.Enabled = False
cmdtambah.Enabled = True
cmdhapus.Enabled = True
Else
cmdsimpan.Enabled = True
cmdbatal.Enabled = True
End If
rs.Close
cnn.CommitTrans
End If
End Sub
Private Sub txtNama_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub
Private Sub mseJumlah_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
End If
End Sub
Private Sub msePotongan_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
End If
End Sub
Private Sub mseSubTotal_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
End If
End Sub
Private Sub mseTotal_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
End If
End Sub
Private Sub txtKeterangan_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub
Private Sub txtKodeBarang_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub
Private Sub txtKodePemasok_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub
Private Sub txtNamaBarang_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub
Private Sub txtNamaPemasok_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub
Private Sub txtNota_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub
Private Sub txtSatuan_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
Else
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End Sub
Sub Kosong()
txtnota.Text = ""
txtkodepemasok.Text = ""
txtnamapemasok.Text = ""
txtketerangan.Text = ""
msesubtotal.Text = ""
msepotongan.Text = ""
msetotal.Text = ""
txtkodebarang.Text = ""
txtnamabarang.Text = ""
txtsatuan.Text = ""
mseharga.Text = ""
msejumlah.Text = ""
Total = 0
End Sub
Sub Detail()
Dim msql As String
msql = "select KodeBarang,NamaBarang," & _
" HargaBeli,Jumlah, Total" & _
" From tbNotaBeliDetail " & _
" Where NoNota='" & txtnota.Text & "'"
Adodc1.RecordSource = msql
Adodc1.Refresh [B]'Stop here[/B]
dgdetail.Refresh
End Sub