Cara Membuat Form User / Kasirpada VB


Setelah membuat Form Login pada penjelasan sebelumnya, kini saatnya kita membuat Form User atau Form Kasir.Dalam form ini Kita bisa memanage User yang bisa Login, Mulaid ari Input, Edit, dan Hapus. Anda bisa melihat Print Screen Form nya Seperti disamping.Bagaimana cara membuatnya?

Caranya adalah :
Anda bisa langsung melihat form diatas,
Kodekasir ( Text1)
NamaKasir ( Text2 )
Status ( Combo1 )
Password ( Text 3 )

Dan pastikan anda sudah membuat database teknikkom.mdb dan membuat Tabel Admin seperti yang sebelumnya  telah kita bahas.
Coding Scripnya adalah sebagai berikut :

Function CariData()
    Call BukaDB
    RSuser.Open "Select * From admin where kodeuser='" & Text1 & "'", koneksi
End Function
Private Sub TampilkanData()
    With RSuser
        If Not RSuser.EOF Then
            Text2 = RSuser!namauser
            Combo1 = RSuser!Status
            Text3 = RSuser!passworduser
        End If
    End With
End Sub
Private Sub KosongkanText()
    Text1 = ""
    Text2 = ""
    Combo1 = ""
    Text3 = ""
End Sub
Private Sub TidakSiapIsi()
    Text1.Enabled = False
    Text2.Enabled = False
    Text3.Enabled = False
    Combo1.Enabled = False
End Sub
Private Sub KondisiAwal()
    KosongkanText
    TidakSiapIsi
    cmdinput.Caption = "&Input"
    cmdedit.Caption = "&Edit"
    cmdhapus.Caption = "&Hapus"
    cmdtutup.Caption = "&Tutup"
    cmdinput.Enabled = True
    cmdedit.Enabled = True
    cmdhapus.Enabled = True
End Sub
Private Sub SiapIsi()
    Text1.Enabled = True
    Text2.Enabled = True
    Text3.Enabled = True
    Combo1.Enabled = True
End Sub
Private Sub AutoNomor()
Call BukaDB
RSuser.Open ("select * from admin Where kodeuser In(Select Max(kodeuser)From admin)Order By kodeuserDesc"), koneksi
RSuser.Requery
    Dim Urutan As String * 6
    Dim Hitung As Long
    With RSuser
        If .EOF Then
            Urutan = "USR" + "001"
            Text1 = Urutan
        Else
            Hitung = Right(!kodeuser, 3) + 1
            Urutan = "USR" + Right("000" &Hitung, 3)
        End If
        Text1 = Urutan
    End With
End Sub
Private Sub Text2_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 Text3.SetFocus
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
    'If KeyAscii = 13 Then cmdinput.SetFocus
End Sub
SubForm_Load()
    Call BukaDB
    Text1.MaxLength = 6
    Text2.MaxLength = 30
    Text3.MaxLength = 20
    Combo1.Clear
        Combo1.AddItem "USER"
        Combo1.AddItem "ADMIN"
    Text3.PasswordChar = "X"
    KondisiAwal
    TidakSiapIsi
End Sub
Private Sub cmdinput_Click()
    If cmdinput.Caption = "&Input" Then
        cmdinput.Caption = "&Simpan"
        cmdedit.Enabled = False
        cmdhapus.Enabled = False
        cmdtutup.Caption = "&Batal"
        SiapIsi
        KosongkanText
        Call AutoNomor
        Text1.Enabled = False
        Text2.SetFocus
    Else
        If Text1 = "" Or Text2 = "" Or Text3 = "" Then
            MsgBox "Data BelumLengkap...!"
        Else
            Dim SQLTambah As String
            SQLTambah = "Insert Into admin (kodeuser,namauser,passworduser,status) values ('" & Text1 & "','" & Text2 & "','" & Text3 & "','" & Combo1 & "')"
            koneksi.ExecuteSQLTambah
            KondisiAwal
        End If
    End If
End Sub
Private Sub cmdedit_Click()
    If cmdedit.Caption = "&Edit" Then
        cmdinput.Enabled = False
        cmdedit.Caption = "&Simpan"
        cmdhapus.Enabled = False
        cmdtutup.Caption = "&Batal"
        SiapIsi
        Text1.SetFocus
    Else
        If Text2 = "" Or Text3 = "" Then
            MsgBox "Masih Ada Data Yang Kosong"
        Else
            Dim SQLEdit As String
            SQLEdit = "Update admin Set namauser= '" & Text2 & "', passworduser='" & Text3 & "', status='" & Combo1 & "' where kodeuser='" & Text1 & "'"
            koneksi.ExecuteSQLEdit
            KondisiAwal
        End If
    End If
End Sub
Private Sub cmdhapus_Click()
    If cmdhapus.Caption = "&Hapus" Then
        cmdinput.Enabled = False
        cmdedit.Enabled = False
        cmdtutup.Caption = "&Batal"
        KosongkanText
        SiapIsi
        Text1.SetFocus
    End If
End Sub

Private Sub cmdtutup_Click()
    Select Case cmdtutup.Caption
        Case "&Tutup"
            Unload Me
        Case "&Batal"
            TidakSiapIsi
            KondisiAwal
    End Select
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then
    If Len(Text1) < 6 Then
        MsgBox "KodeHarus 6 Digit"
        Text1.SetFocus
    Else
        Text2.SetFocus
    End If

    Ifcmdinput.Caption = "&Simpan" Then
        Call CariData
            If Not RSuser.EOF Then
                TampilkanData
                MsgBox "KodeAnggotaSudah Ada"
                KosongkanText
                TxtNomor.SetFocus
            Else
                TxtNama.SetFocus
            End If
    End If
   
    Ifcmdedit.Caption = "&Simpan" Then
        Call CariData
            If Not RSuser.EOF Then
                TampilkanData
                Text1.Enabled = False
                Text2.SetFocus
            Else
                MsgBox "KodeAnggotaTidak Ada"
                Text1 = ""
                Text1.SetFocus
            End If
    End If
    Ifcmdhapus.Enabled = True Then
        Call CariData
            If Not RSuser.EOF Then
                TampilkanData
                Pesan = MsgBox("Yakin akandihapus", vbYesNo)
                If Pesan = vbYes Then
                    Dim SQLHapus As String
                    SQLHapus = "Delete From admin where kodeuser= '" & Text1 & "'"
                    koneksi.ExecuteSQLHapus
                    KondisiAwal
                Else
                    KondisiAwal
                    cmdhapus.SetFocus
                End If
            Else
                MsgBox "Data Tidakditemukan"
                Text1.SetFocus
            End If
    End If
End If
End Sub

Mudahbukan :) SelamatBelajar :)

0 Response to "Cara Membuat Form User / Kasirpada VB"

Posting Komentar

powered by Blogger | WordPress by Newwpthemes | Converted by BloggerTheme