Aplikasi Penjualan Dengan Visual Basic 6 – 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

Sub HiddenPassword()
    Call Koneksi
    Adodc1.ConnectionString = LokasiData
    Adodc1.RecordSource = "TBLUsers"
    Set DataGrid1.DataSource = Adodc1
    Adodc1.Recordset.MoveFirst
    Do While Not Adodc1.Recordset.EOF
        Adodc1.Recordset!pwdkasir = "*****"
        Adodc1.Recordset.MoveNext
    Loop
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 Koneksi
    RSKasir.Open "SELECT * FROM TBLUsers WHERE namakasir LIKE '%" & Text4 & "%'", CONN
    RSKasir.Requery
    If RSKasir.EOF Then
        MsgBox "tidak ada data ditemukan", vbInformation, "Information"
    Else
        Adodc1.ConnectionString = LokasiData
        Adodc1.RecordSource = "SELECT * FROM TBLUsers WHERE namakasir LIKE '%" & Text4 & "%'"
        Adodc1.Refresh
        Set DataGrid1.DataSource = Adodc1
        DataGrid1.Refresh
        Adodc1.Recordset.MoveFirst
        Call HiddenPassword
        Call AturDataGrid
    End If
    
End Sub

Private Sub Form_Activate()
    Call Koneksi
    Adodc1.ConnectionString = LokasiData
    Adodc1.RecordSource = "TBLUsers"
    Adodc1.Refresh
    Set DataGrid1.DataSource = Adodc1
    DataGrid1.Refresh
    Call HiddenPassword
    Call AturDataGrid
    Call TampilLevel
    
End Sub

Private Sub Form_Load()
    Call Koneksi
    Call Kosongkan
End Sub


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..

Ali Akbar

Software Developer yang fokus mengembangkan aplikasi berbasis Web dan Desktop. Senang mempelajari teknologi baru terutama di bidang web design dan web development.

View all posts by Ali Akbar →

Tinggalkan Balasan

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