Aplikasi Penjualan Dengan Visual Basic 6 – Part 3 – CRUD Data User

Aplikasi Penjualan VB6 Part 3 CRUD Data User

Silahkan anda buat desain form seperti dibawah ini

Aplikasi Penjualan Dengan Visual Basic 6

Kemudian masuk ke jendela kode dan copykan source code dibawah ini


Sub Kosongkan()
    Text1 = ""
    Text2 = ""
    Text3 = ""
    Text4 = ""
    Combo1 = ""
    
End Sub

Sub DataBaru()
    Text2 = ""
    Text3 = ""
    Text4 = ""
    Combo1 = ""
    Text2.SetFocus
    
End Sub

Sub Ketemu()
    On Error Resume Next
    Text2 = RSKasir!namakasir
    Text3 = RSKasir!pwdkasir
    Combo1 = RSKasir!Status
    Text2.SetFocus
    
End Sub

Sub CariData()
    Call Koneksi
    RSKasir.Open "SELECT * FROM TBLUsers WHERE kodekasir='" & Text1 & "'", CONN
    RSKasir.Requery
    
End Sub

Sub TampilLevel()
    Call Koneksi
    RSKasir.Open "SELECT DISTINCT status FROM TBLUsers", CONN
    RSKasir.Requery
    Combo1.Clear
    Do While Not RSKasir.EOF
        Combo1.AddItem RSKasir!Status
        RSKasir.MoveNext
    Loop
    
End Sub

Sub AturDataGrid()
    DataGrid1.HeadLines = 1.5
    DataGrid1.Columns(0).Caption = "Kode"
    DataGrid1.Columns(1).Caption = "Nama Lengkap"
    DataGrid1.Columns(1).Width = 2700
    DataGrid1.Columns(2).Caption = "Password"
    DataGrid1.Columns(3).Caption = "Level"
End Sub

' Samarkan password di query, BUKAN di data.
' Versi lama mengisi pwdkasir = "*****" pada recordset Adodc1, dan ADO ikut
' menyimpannya ke database saat MoveNext sehingga semua password berubah.
Sub HiddenPassword(Optional ByVal Cari As String = "")
    Adodc1.ConnectionString = LokasiData
    Adodc1.RecordSource = "SELECT KodeKasir, NamaKasir, '*****' AS PwdKasir, Status FROM TBLUsers WHERE NamaKasir LIKE '%" & Replace(Cari, "'", "''") & "%' ORDER BY KodeKasir"
    Adodc1.Refresh
    Set DataGrid1.DataSource = Adodc1
    DataGrid1.Refresh
End Sub

Private Sub Command1_Click()
    If Text1 = "" Or Text2 = "" Or Text3 = "" Or Combo1 = "" Then
        MsgBox "Data belum lengkap", vbExclamation, "Warning"
        Exit Sub
    Else
        Call CariData
        If RSKasir.EOF Then
            SQLSimpan = "INSERT INTO TBLUsers VALUES ('" & Text1 & "','" & Text2 & "','" & Text3 & "','" & Combo1 & "')"
            CONN.Execute SQLSimpan
        Else
            SQLEdit = "UPDATE TBLUsers SET  Namakasir='" & Text2 & "', pwdkasir='" & Text3 & "', status='" & Combo1 & "' WHERE kodekasir='" & Text1 & "'"
            CONN.Execute SQLEdit
        End If
        Call Kosongkan
        Call Form_Activate
        Text1.SetFocus
    End If
    
End Sub

Private Sub Command2_Click()
    If Text1 = "" Then
        MsgBox "ID masih kosong...", vbExclamation, "Warning"
        Text1.SetFocus
        Exit Sub
    Else
        pesan = MsgBox("Yakin akan hapus data ini ...?", vbYesNo, "Information")
        If pesan = vbYes Then
            hapus = "DELETE * FROM TBLUsers WHERE kodekasir='" & Text1 & "'"
            CONN.Execute hapus
            Call Kosongkan
            Call Form_Activate
            Text1.SetFocus
        Else
            Call Kosongkan
            Text1.SetFocus
        End If
    End If
        
End Sub

Private Sub Command3_Click()
    Call Kosongkan
    Text1.SetFocus
End Sub

Private Sub Command4_Click()
    Unload Me
End Sub

Private Sub exit_Click()
    Unload Me
End Sub

Private Sub help_Click()
    FormAbout.Show vbModal
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
    If KeyAscii = 13 Then
        If Text1 = "" Then
            MsgBox "ID tidak boleh kosong"
            Text1.SetFocus
            Exit Sub
        Else
            Call CariData
            If RSKasir.EOF Then
                Call DataBaru
            Else
                Call Ketemu
            End If
        End If
    End If
            
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
    If KeyAscii = 13 Then Text3.SetFocus
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
    If KeyAscii = 13 Then Combo1.SetFocus
End Sub

Private Sub Combo1_KeyPress(KeyAscii As Integer)
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
    If KeyAscii = 13 Then Command1.SetFocus
End Sub

Private Sub Text4_Change()
    Call HiddenPassword(Text4)
    Call AturDataGrid
End Sub

Private Sub Form_Activate()
    Call Koneksi
    Call HiddenPassword
    Call AturDataGrid
    Call TampilLevel

End Sub

Private Sub Form_Load()
    Call Koneksi
    Call Kosongkan
End Sub


Pembaruan November 2026: versi awal Sub HiddenPassword menyamarkan password dengan mengubah isi recordset Adodc1. Ternyata ADO ikut menyimpan perubahan itu ke database, sehingga setiap kali form ini dibuka semua password di TBLUsers berubah menjadi ***** dan kasir tidak bisa login. Kode di atas sudah diperbaiki: password kini disamarkan di query (kolom '*****' AS PwdKasir), jadi data asli tidak tersentuh. Selain itu, pencarian di Text4 sekarang benar-benar menyaring grid. Jika password di database Anda terlanjur menjadi *****, buka DBPenjualan.mdb di MS Access lalu isi ulang kolom PwdKasir. Pembahasan lengkapnya ada di Part 5 – Form Login Kasir.

Tampilan akhir dari desain dan coding diatas adalah sebagai berikut

Aplikasi Penjualan Dengan Visual Basic 6

Daftar semua artikel untuk tutorial Cara Membuat Aplikasi Penjualan Dengan Visual Basic 6 ini..

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *