0% found this document useful (0 votes)
44 views21 pages

Fungsi Cod

This document contains VBA code for an invoice form in Microsoft Access. It includes event handlers and procedures for loading the form, adding/deleting/saving records, calculating totals, exporting to Excel, and other form functionality. Key events handled include clicking buttons for search, save, delete, export, as well as updating fields and records.

Uploaded by

salmira82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views21 pages

Fungsi Cod

This document contains VBA code for an invoice form in Microsoft Access. It includes event handlers and procedures for loading the form, adding/deleting/saving records, calculating totals, exporting to Excel, and other form functionality. Key events handled include clicking buttons for search, save, delete, export, as well as updating fields and records.

Uploaded by

salmira82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 21

Dim Rs As DAO.

Recordset

Option Compare Database

Private Sub alamat_AfterUpdate()

On Error Resume Next

alamat.Requery

'refresh

End Sub

Private Sub cmdBukaKunci_Click()

On Error Resume Next

DoCmd.OpenForm "lgn_buka_kunci"

Form_lgn_buka_kunci.Caption = "Buka Kunci"

End Sub

Private Sub cmdCariAWB_Click()

On Error Resume Next

On Error GoTo Err_btnSearch_Click

Dim strCriteria As String

Dim rst As DAO.Recordset

Dim strSearch As String

strSearch = InputBox("Pencarian", "DLB Express", "Masukkan nomer AWB")


Set rst = Form_invoice_cod_pecahan_detail.RecordsetClone

strCriteria = "[no_awb] like '*" & strSearch & "*'"

rst.FindFirst strCriteria

If Not rst.NoMatch Then

If Not rst.EOF Then Form_invoice_cod_pecahan_detail.Bookmark = rst.Bookmark

Else ' If no Match

MsgBox "Nomer AWB itu tidak ada!", vbInformation, "Info"

End If

rst.Close

Exit_btnSearch_Click:

Set rst = Nothing

Exit Sub

Err_btnSearch_Click:

MsgBox err.Description

Resume Exit_btnSearch_Click

End Sub

Private Sub cmdExcel_Click()

'Kalau error
On Error GoTo pesan

Dim stroutputDir As String

Dim strDefaultDB As String

'Get current value of default directory, so that you can reset it after

'you are finished

strDefaultDB = GetOption("Default Database Directory")

'Set the output directory to YOUR_DIRECTORY_HERE

stroutputDir = "d:\backup"

SetOption "Default Database Directory", stroutputDir

DoCmd.OutputTo acOutputQuery, "qryinvoice_cod_pecahan", acFormatXLSX, , True

'Set the output directory back to its original value

SetOption "Default Database Directory", strDefaultDB

Dim xlApp As Object

On Error Resume Next

Set xlApp = GetObject(, "Excel.Application")

If err.Number <> 0 Then

'Excel wasn't running, start it from cod_pecahane

Set xlApp = CreateObject("Excel.Application")


End If

On Error GoTo 0

'MsgBox strOutputDir

xlApp.Workbooks.Open stroutputDir & "\" & "qryinvoice_cod_pecahan.xlsx"

Exit Sub

pesan:

MsgBox "Harap Microsoft Excelnya ditutup dulu!", vbInformation, "Perhatian"

End Sub

Private Sub Form_Current()

On Error Resume Next

DoCmd.Maximize

Dim ctrl As control

If Me!yprinted = -1 Then

For Each ctrl In Me.Controls

If TypeOf ctrl Is TextBox Or TypeOf ctrl Is SubForm Then

ctrl.Locked = True

End If

Next
Else

For Each ctrl In Me.Controls

If TypeOf ctrl Is TextBox Or TypeOf ctrl Is SubForm Then

ctrl.Locked = False

End If

Next

End If

End Sub

Private Sub cmdCetak_Click()

On Error Resume Next

MsgBox "Jangan lupa cek total dulu sebelum cetak invoice!", vbInformation, "Peringatan"

usr = "eka"

Me!yprinted = -1

Forms!pilihanCetak.Caption = Screen.ActiveForm.Name

DoCmd.OpenForm "pilihanCetak"

Forms!pilihanCetak.Caption = "invoice_cod_pecahan"

Dim ctrl As control


For Each ctrl In Me.Controls

If TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox Or TypeOf ctrl Is SubForm Then

ctrl.Locked = True

End If

Next

End Sub

Private Sub cmdDataBaru_Click()

On Error Resume Next

Dim bulan_romawi, Urut

Select Case bulan

Case 1

bulan_romawi = "I"

Case 2

bulan_romawi = "II"

Case 3

bulan_romawi = "III"

Case 4
bulan_romawi = "IV"

Case 5

bulan_romawi = "V"

Case 6

bulan_romawi = "VI"

Case 7

bulan_romawi = "VII"

Case 8

bulan_romawi = "VIII"

Case 9

bulan_romawi = "IX"

Case 10

bulan_romawi = "X"

Case 11

bulan_romawi = "XI"

Case 12

bulan_romawi = "XII"
End Select

Set Rs = CurrentDb.OpenRecordset("select * from invoice_cod_pecahan")

If Rs.RecordCount > 0 Then Rs.MoveLast

Urut = Rs.RecordCount + 1

customer.SetFocus

DoCmd.GoToRecord , , acNewRec

no_invoice = String(4 - Len(Urut), "0") & Urut & "/DLB-DPS/INV-OUT/" & bulan_romawi & "/" & tahun

End Sub

Private Sub cmdHapus_Click()

On Error Resume Next

DoCmd.SetWarnings False

Dim norut As String

norut = CurrentRecord

If MsgBox("Apa anda yakin mau menghapus data ini?", vbInformation + vbYesNo, "Info") = vbYes Then

DoCmd.OpenForm "lgn_buka_kunci"

Form_lgn_buka_kunci.Caption = "cod hapus benar"

'DoCmd.RunSQL "delete * from invoice_cod_pecahan_detail where invoice_pecahan = forms!


invoice_cod_pecahan!no_invoice"

'DoCmd.RunSQL "delete * from invoice_cod_pecahan where no_invoice = forms!invoice_cod_pecahan!


no_invoice"
'RecordSource = "invoice_cod_pecahan"

'DoCmd.GoToRecord , , acGoTo, norut - 1

End If

End Sub

Private Sub cmdKeluar_Click()

On Error Resume Next

DoCmd.Close

DoCmd.SetWarnings False

'DoCmd.RunSQL "delete * from invoice_cod_pecahan"

End Sub

Private Sub cmdUrutkanTanggal_Click()

On Error Resume Next

Form_invoice_cod_pecahan_detail.OrderByOn = True

Form_invoice_cod_pecahan_detail.OrderBy = "pengirim_tgl, no_awb"

Requery

End Sub

Private Sub cmdUrutNomer_Click()

On Error Resume Next

Form_invoice_cod_pecahan_detail.OrderByOn = True

Form_invoice_cod_pecahan_detail.OrderBy = "nom"
End Sub

Private Sub combo1_DblClick(Cancel As Integer)

On Error Resume Next

DoCmd.OpenForm "customer"

End Sub

Private Sub customer_GotFocus()

On Error Resume Next

If Me!yprinted = 0 Then

Dim ctrl As control

For Each ctrl In Me.Controls

If TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox Or TypeOf ctrl Is OptionButton Or TypeOf ctrl Is
SubForm Then

ctrl.Locked = False

End If

Next

End If

End Sub

Private Sub Form_Activate()

On Error Resume Next


Me!qty_header = DSum("qty", "invoice_cod_pecahan_detail", "invoice_pecahan= Forms!
invoice_cod_pecahan!no_invoice")

With Form_invoice_cod_pecahan_detail

.yKunciHargaAll = .yKunciHarga

End With

End Sub

Private Sub Form_Error(DataErr As Integer, Response As Integer)

On Error Resume Next

If DataErr = 7787 Then

Response = acDataErrContinue

Me.Recordset.MovePrevious

Me.Recordset.MoveNext

End If

End Sub

Private Sub cmdSimpan_Click()

On Error Resume Next

DoCmd.SetWarnings False

Dim invoice

invoice = Forms!invoice_cod_pecahan!no_invoice

Dim Rs As Recordset
Set Rs = CurrentDb.OpenRecordset("select * from invoice_cod_pecahan where no_invoice = '" & Forms!
invoice_cod_pecahan!no_invoice & "'")

If Rs.RecordCount > 0 Then Rs.MoveLast

'MsgBox Rs.RecordCount

If Rs.RecordCount <= 0 Then

DoCmd.RunSQL "insert into


invoice_cod_pecahan(tgl_invoice,no_invoice,customer,coli,kg,subtotal_invoice,ppn,total_invoice,dibayar
,tgl_dibayar,nama_penerima,keterangan_ttd)" _

& "values ('" & Format(tgl_invoice, "yyyy-mm-dd") & "' , '" & no_invoice & "','" & customer & "','" & coli
& "','" & kg & "','" & subtotal_invoice & "','" & ppn & "','" & total_invoice & "','" & dibayar & "','" &
Format(tgl_dibayar, "yy-mm-dd") & "','" & nama_penerima & "','" & keterangan_ttd & "')"

Else

DoCmd.RunSQL "update invoice_cod_pecahan set tgl_invoice='" & Format(tgl_invoice, "yyyy-mm-dd") &


"',no_invoice='" & no_invoice & "',customer='" & customer & "',coli='" & coli & "',kg='" & kg &
"',total_invoice='" & total_invoice & "',dibayar='" & dibayar & "',tgl_dibayar='" & Format(tgl_dibayar, "yy-
mm-dd") & "',nama_penerima='" & nama_penerima & "',keterangan_ttd='" & keterangan_ttd & "' where
id =" & Forms!invoice_cod_pecahan!id

End If

Set Rs = CurrentDb.OpenRecordset("select * from invoice_cod_pecahan where no_invoice = '" & Forms!


invoice_cod_pecahan!no_invoice & "'")

'Form_invoice_cod_pecahan_detail.Requery

'refresh

DoCmd.GoToControl "invoice_cod_pecahan_detail"

'Form_invoice_cod_pecahan_detail.no_awb.SetFocus

DoCmd.GoToRecord , , acFirst

For I = 1 To Form_invoice_cod_pecahan_detail.Recordset.RecordCount

DoCmd.RunSQL "update invoice_cod_pecahan_detail set id = '" & Rs!id & "' where id_detail = forms!
invoice_cod_pecahan!invoice_cod_pecahan_detail!id_detail"
DoCmd.GoToRecord , , acNext

Next I

DoCmd.GoToRecord , , acPrevious

txtCari.Requery

Dim sumber_data1 As String

Set Rs = CurrentDb().OpenRecordset("select * from invoice_cod_pecahan")

sumber_data1 = "SELECT * FROM invoice_cod_pecahan where no_invoice = '" & invoice & "'"

Form_invoice_cod_pecahan.RecordSource = sumber_data1

'refresh

MsgBox "Data suda disimpan!", vbInformation, "Info"

End Sub

Private Sub customer_AfterUpdate()

On Error Resume Next

Dim Rs As Recordset

customer.Requery

Refresh

Set Rs = CurrentDb.OpenRecordset("select * from customer where nama = '" & customer & "'")

If Rs.RecordCount > 0 Then Rs.MoveLast

If Rs.RecordCount = 0 Then

If MsgBox("Nama combo1 itu tidak ada di database, apaka anda mau menambahkannya?", vbYesNo +
vbInformation, "Info") = vbYes Then

DoCmd.OpenForm "customer_single"

Form_customer_single.nama = customer

Forms!customer_single!pilihan = "Outbound"
Form_customer_single.alamat.SetFocus

End If

End If

End Sub

Private Sub Form_Load()

On Error Resume Next

Form_invoice_cod_pecahan.MinMaxButtons = 3

Dim ctrl As control

If Me!yprinted = True Then

For Each ctrl In Me.Controls

If TypeOf ctrl Is TextBox Or TypeOf ctrl Is SubForm Then

ctrl.Locked = True

End If

Next

Else

For Each ctrl In Me.Controls

If TypeOf ctrl Is TextBox Or TypeOf ctrl Is SubForm Then

ctrl.Locked = False
End If

Next

End If

'jumlsh_line

'Biaya Kirim

With Form_invoice_cod_pecahan_detail

If .pengali = "berat" Or IsNull(.pengali) Or IsNull(.pengali) Then

.biaya_kirim = Nz(.jenis_packing * .tarif) + Nz(.biaya_packing)

Else

.biaya_kirim = Nz(.qty * .tarif) + Nz(.biaya_packing)

.biaya_kirim.Requery

End If

End With

Refresh

Dim total As Currency

Set Rs = Form_invoice_cod_pecahan_detail.RecordsetClone
While Not Rs.EOF

total = total + Nz(Rs!biaya_kirim)

Rs.MoveNext

Wend

If Form_invoice_cod_pecahan.yKunciSubtotal = False And total <> 0 Then


Form_invoice_cod_pecahan.subtotal_invoice = total

penomeran

Form_invoice_cod_pecahan.ppn = 0

If Form_invoice_cod_pecahan.yKunciTotal = False Then Form_invoice_cod_pecahan.total_invoice =


Nz(Form_invoice_cod_pecahan.subtotal_invoice)

Dim Urut As Long

Set Rs = Form_invoice_cod_pecahan_detail.RecordsetClone
Rs.MoveFirst

Do Until Rs.EOF

Urut = Urut + 1

Rs.Edit

Rs!nom = Urut

Rs.Update

Rs.MoveNext

Loop

Form_invoice_cod_pecahan_detail.Requery

Refresh

Me!qty_header = DSum("qty", "invoice_cod_pecahan_detail", "invoice_pecahan= Forms!


invoice_cod_pecahan!no_invoice")

End Sub

Private Sub txtCari_AfterUpdate()


On Error Resume Next

Dim sumber_data1 As String

Dim Rs As Recordset

Set Rs = CurrentDb().OpenRecordset("select * from invoice_cod_pecahan")

sumber_data1 = "SELECT * FROM invoice_cod_pecahan where id = " & txtCari & ""

Form_invoice_cod_pecahan.RecordSource = sumber_data1

'refresh

End Sub

Private Sub no_invoice_AfterUpdate()

On Error Resume Next

Dim Rs As DAO.Recordset

Dim Rt As DAO.Recordset

Set Rs = CurrentDb.OpenRecordset("select * from invoice_cod_pecahan where no_invoice = '" &


no_invoice & "'")

If Rs.RecordCount > 0 Then Rs.MoveLast

If Rs.RecordCount > 0 Then

MsgBox "Nomer itu sudah digunakan!", vbInformation, "Info"

Else

Dim invoice

invoice = no_invoice.OldValue

Set Rs = CurrentDb.OpenRecordset("select * from invoice_cod_pecahan_detail where invoice_pecahan =


'" & invoice & "'")

Set Rt = CurrentDb.OpenRecordset("select * from TerimaPembayaranDariCustomer where no_invoice =


'" & invoice & "'")

Do Until Rs.EOF

Rs.Edit
Rs!invoice_pecahan = no_invoice

Rs.Update

Rs.MoveNext

Loop

Form_invoice_cod_detail.Requery

Refresh

End If

Rt.Edit

Rt!no_invoice = no_invoice

Rt.Update

End Sub

Private Sub ppn_AfterUpdate()

On Error Resume Next

If Form_invoice_cod_pecahan.yKunciTotal = False Then total_invoice = Nz(subtotal_invoice) + Nz(ppn)

End Sub

Sub jumlsh_line()

On Error Resume Next

If Me!yprinted = 0 Then

DoCmd.GoToControl "invoice_cod_pecahan_detail"

With Form_invoice_cod_pecahan_detail

DoCmd.GoToRecord , , acFirst

If yKunciBiayaKirim = 0 Then .biaya_kirim = Nz(.qty * .tarif) + Nz(.biaya_packing) '- Nz(.discount)

Do While .qty > 0


If yKunciBiayaKirim = 0 Then .biaya_kirim = Nz(.qty * .tarif) + Nz(.biaya_packing) '- Nz(.discount)

DoCmd.GoToRecord , , acNext

Loop

.Undo

End With

End If

End Sub

Sub penomeran()

Dim Urut As Long

Set Rs = Form_invoice_cod_pecahan_detail.RecordsetClone

Rs.MoveFirst

Do Until Rs.EOF

Urut = Urut + 1

Rs.Edit

Rs!nom = Urut
Rs.Update

Rs.MoveNext

Loop

Form_invoice_cod_pecahan_detail.Requery

Refresh

End Sub

You might also like