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, Mulai dari Input, Edit, dan Hapus. Anda bisa melihat Print Screen Form nya seperti diatas. Bagaimana cara membuatnya?
Caranya adalah :
Anda bisa langsung melihat form diatas,
Kode kasir ( Text1)
Nama Kasir ( Text2 )
Status ( Combo1 )
Password ( Text 3 )
Dan pastikan anda sudah membuat database dbvainit.mdb dan membuat Table 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 kodeuser Desc"), 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
Sub Form_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 Belum Lengkap...!"
Else
Dim SQLTambah As String
SQLTambah = "Insert Into admin (kodeuser,namauser,passworduser,status) values ('" & Text1 & "','" & Text2 & "','" & Text3 & "','" & Combo1 & "')"
koneksi.Execute SQLTambah
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.Execute SQLEdit
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 "Kode Harus 6 Digit"
Text1.SetFocus
Else
Text2.SetFocus
End If
If cmdinput.Caption = "&Simpan" Then
Call CariData
If Not RSuser.EOF Then
TampilkanData
MsgBox "Kode Anggota Sudah Ada"
KosongkanText
TxtNomor.SetFocus
Else
TxtNama.SetFocus
End If
End If
If cmdedit.Caption = "&Simpan" Then
Call CariData
If Not RSuser.EOF Then
TampilkanData
Text1.Enabled = False
Text2.SetFocus
Else
MsgBox "Kode Anggota Tidak Ada"
Text1 = ""
Text1.SetFocus
End If
End If
If cmdhapus.Enabled = True Then
Call CariData
If Not RSuser.EOF Then
TampilkanData
Pesan = MsgBox("Yakin akan dihapus", vbYesNo)
If Pesan = vbYes Then
Dim SQLHapus As String
SQLHapus = "Delete From admin where kodeuser= '" & Text1 & "'"
koneksi.Execute SQLHapus
KondisiAwal
Else
KondisiAwal
cmdhapus.SetFocus
End If
Else
MsgBox "Data Tidak ditemukan"
Text1.SetFocus
End If
End If
End If
End Sub