Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Coding Form Sales

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

CODING FORM SALES

Option Explicit

Private Sub CMDHAPUS_Click()

Application.ScreenUpdating = False

Dim HapusData As Object

Me.TABELSALES.Value = ""

If Me.TXTNOMOR.Value = "" Then

Call MsgBox("Pilih data pada tabel data", vbInformation, "Hapus Data")

Else

'Membuat pesan konfirmasi hapus data

Select Case MsgBox("Anda akan menghapus data" _

& vbCrLf & "Apakah anda yakin?" _

, vbYesNo Or vbQuestion Or vbDefaultButton1, "Hapus data")

Case vbNo

Exit Sub

Case vbYes

End Select

Sheet3.Select

Selection.EntireRow.Delete

Me.TXTID.Value = ""

Me.TXTNAMA.Value = ""

Me.CMBJENISKELAMIN.Value = ""

Me.TXTALAMAT.Value = ""

Me.TXTTELPON.Value = ""

Me.TXTNOMOR.Value = ""

Call MsgBox("Data berhasil dihapus", vbInformation, "Hapus Data")

Sheet1.Select

End If
End Sub

Private Sub CMDRESET_Click()

Me.TXTID.Value = ""

Me.TXTNAMA.Value = ""

Me.CMBJENISKELAMIN.Value = ""

Me.TXTALAMAT.Value = ""

Me.TXTTELPON.Value = ""

Me.TXTNOMOR.Value = ""

Me.TABELSALES.Value = ""

Me.CMDSIMPAN.Caption = "Save"

End Sub

Private Sub CMDSIMPAN_Click()

Dim DBSales As Object

Set DBSales = Sheet3.Range("A20000").End(xlUp)

If Me.CMDSIMPAN.Caption = "Save" Then

If Me.TXTID.Value = "" _

Or Me.TXTNAMA.Value = "" _

Or Me.CMBJENISKELAMIN.Value = "" _

Or Me.TXTALAMAT.Value = "" _

Or Me.TXTTELPON.Value = "" Then

Call MsgBox("Harap isi data barang dengan lengkap", vbInformation, "Data Barang")

Else

DBSales.Offset(1, 0).Value = "=ROW()-ROW($A$5)"

DBSales.Offset(1, 1).Value = Me.TXTID.Value

DBSales.Offset(1, 2).Value = Me.TXTNAMA.Value

DBSales.Offset(1, 3).Value = Me.CMBJENISKELAMIN.Value

DBSales.Offset(1, 4).Value = Me.TXTALAMAT.Value

DBSales.Offset(1, 5).Value = Me.TXTTELPON.Value

Me.CMBJENISKELAMIN.Clear
Call UserForm_Initialize

Call MsgBox("Data Sales berhasil ditambah", vbInformation, "Sales")

Me.TXTID.Value = ""

Me.TXTNAMA.Value = ""

Me.CMBJENISKELAMIN.Value = ""

Me.TXTALAMAT.Value = ""

Me.TXTTELPON.Value = ""

End If

Else

Call UpdateSales

End If

End Sub

Private Sub UpdateSales()

Application.ScreenUpdating = False

'Perintah membuat Sumber data yang diubah

Dim UbahData As Object

'Perintah mengecek apakah ada data yang diubah

If Me.TXTNOMOR.Value = "" Then

Call MsgBox("Untuk mengubah Data, Pilih data terlebih dahulu", vbInformation, "Ubah Data")

Else

Set UbahData = Sheet3.Range("A6:A900000").Find(What:=Me.TXTNOMOR.Value, LookIn:=xlValues)

'Perintah mengubah data dari kolom pertama

UbahData.Offset(0, 1).Value = Me.TXTID.Value

UbahData.Offset(0, 2).Value = Me.TXTNAMA.Value

UbahData.Offset(0, 3).Value = Me.CMBJENISKELAMIN.Value

UbahData.Offset(0, 4).Value = Me.TXTALAMAT.Value

UbahData.Offset(0, 5).Value = Me.TXTTELPON.Value

'Perintah memunculkan pesan bahwa data berhasil diubah

Call MsgBox("Data berhasil diubah", vbInformation, "Ubah Data")


'Perintah membersihkan textbox

Me.TXTID.Value = ""

Me.TXTNAMA.Value = ""

Me.CMBJENISKELAMIN.Value = ""

Me.TXTALAMAT.Value = ""

Me.TXTTELPON.Value = ""

Me.TXTNOMOR.Value = ""

Me.CMDSIMPAN.Caption = "Save"

End If

End Sub

Private Sub TABELSALES_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

Application.ScreenUpdating = False

Dim SUMBERUBAH As String

Dim CELLAKTIF As String

On Error GoTo EXCELVBA

Me.TXTNOMOR.Value = Me.TABELSALES.Value

Me.TXTID.Value = Me.TABELSALES.Column(1)

Me.TXTNAMA.Value = Me.TABELSALES.Column(2)

Me.CMBJENISKELAMIN.Value = Me.TABELSALES.Column(3)

Me.TXTALAMAT.Value = Me.TABELSALES.Column(4)

Me.TXTTELPON.Value = Me.TABELSALES.Column(5)

Me.CMDSIMPAN.Caption = "Update"

Sheet3.Select

SUMBERUBAH = Sheets("SALES").Cells(Rows.Count, "A").End(xlUp).Row

Sheets("SALES").Range("A6:A" & SUMBERUBAH).Find(What:=Me.TXTNOMOR.Value,


LookIn:=xlValues, LookAt:=xlWhole).Activate

CELLAKTIF = ActiveCell.Row

Sheet1.Select

Exit Sub
EXCELVBA:

Call MsgBox("Klik pada tabel data sales", vbInformation, "Data Sales")

End Sub

Private Sub UserForm_Initialize()

Dim DSALES As Long

Dim iRow As Long

iRow = Sheet3.Range("A" & Rows.Count).End(xlUp).Row

DSALES = Application.WorksheetFunction.CountA(Sheet3.Range("A6:F90000"))

If DSALES = 0 Then

Me.TABELSALES.RowSource = ""

Else

Me.TABELSALES.RowSource = "SALES!A6:F" & iRow

End If

With CMBJENISKELAMIN

.AddItem "Laki - Laki"

.AddItem "Perempuan"

End With

End Sub

You might also like