Kali ini kita akan belajar cara membuat Form Login dengan Level Akses, disini saya akan memberi contoh dengan 2 level akses terlebih dahulu, sisanya silakan bereksperimen sendiri yaa..
Pertama Buatlah sebuah Database dengan Microsoft Access dengan Nama "DB_User" & Nama Field "Login" kemudian Simpan dengan Format.mdb (Access 2002-2003).
Contoh Database :
Selanjutnya buatlah 2 buah Form dimana :
- Form 1 Sebagai Login
- Form 2 Sebagai Menu Utama
Contoh Tampilan :
1. Form 1 (Login)
Object Properties :
TextBox 1 = ( Property : Name : Text1 )
TextBox 2 = ( Property : Name : Text2 )
TextBox 2 = ( Property : PasswordChar : * ) - Ket : Tanda Bintang
Label 1 = ( Property : Name : Label1 - Caption : USER ID )
Label 2 = ( Property : Name : Label2 - Caption : PASSWORD )
CommandButton 1 = ( Property : Name : Command1 - Caption : LOGIN )
Adodc = ( Property : Name : Adodc1 )
Adodc = ( Property : Visible : False )
TextBox 2 = ( Property : Name : Text2 )
TextBox 2 = ( Property : PasswordChar : * ) - Ket : Tanda Bintang
Label 1 = ( Property : Name : Label1 - Caption : USER ID )
Label 2 = ( Property : Name : Label2 - Caption : PASSWORD )
CommandButton 1 = ( Property : Name : Command1 - Caption : LOGIN )
Adodc = ( Property : Name : Adodc1 )
Adodc = ( Property : Visible : False )
2. Form 2 (Menu Utama)
Object Properties :
TextBox 1 = ( Property : Name : TxtUser )
TextBox 2 = ( Property : Name : TxtNama )
TextBox 3 = ( Property : Name : TxtJabatan )
TextBox 1 = ( Property : Locked : True )
TextBox 2 = ( Property : Locked : True )
TextBox 3 = ( Property : Locked : True )
Label 1 = ( Property : Name : Label1 - Caption : USER ID )
Label 2 = ( Property : Name : Label2 - Caption : NAMA )
Label 3 = ( Property : Name : Label3 - Caption : JABATAN )
CommandButton 1 = ( Property : Name : cmd_barang - Caption : DATA BARANG )
CommandButton 2 = ( Property : Name : cmd_datapel - Caption : DATA PELANGGAN )
CommandButton 3 = ( Property : Name : cmd_trans - Caption : DATA TRANSAKSI )
CommandButton 4 = ( Property : Name : cmd_logout - Caption : LOGOUT )
TextBox 2 = ( Property : Name : TxtNama )
TextBox 3 = ( Property : Name : TxtJabatan )
TextBox 1 = ( Property : Locked : True )
TextBox 2 = ( Property : Locked : True )
TextBox 3 = ( Property : Locked : True )
Label 1 = ( Property : Name : Label1 - Caption : USER ID )
Label 2 = ( Property : Name : Label2 - Caption : NAMA )
Label 3 = ( Property : Name : Label3 - Caption : JABATAN )
CommandButton 1 = ( Property : Name : cmd_barang - Caption : DATA BARANG )
CommandButton 2 = ( Property : Name : cmd_datapel - Caption : DATA PELANGGAN )
CommandButton 3 = ( Property : Name : cmd_trans - Caption : DATA TRANSAKSI )
CommandButton 4 = ( Property : Name : cmd_logout - Caption : LOGOUT )
Selanjutnta Buatlah koneksi Adodc dengan Database Access yang tadi dibuat.
Lihat Tutorial Koneksi Database Access dengan Adodc VB 6.
Jika Sudah, Ganti Property Pages Adodc nya seperti Berikut ;
- Command Type : adCmdText
- Command Text (SQL) : Select * From Login
3. Kodingan untuk Button Login.
Adodc1.RecordSource = "Select * From Login Where User_ID='" + Text1.Text + "' and Password='" + Text2.Text + "'"
Adodc1.Refresh
If Adodc1.Recordset.EOF Then
MsgBox "Username/Password Salah", vbCritical, "Akses Ditolak"
Adodc1.Refresh
Text1.SetFocus
Else
If Adodc1.Recordset.Fields("Jabatan") = "Manager" Then
Form2.cmd_barang.Enabled = True
Form2.cmd_datapel.Enabled = True
Form2.cmd_trans.Enabled = True
Form2.TxtUser.Text = Adodc1.Recordset.Fields("User_ID")
Form2.TxtNama.Text = Adodc1.Recordset.Fields("Nama")
Form2.TxtJabatan.Text = Adodc1.Recordset.Fields("Jabatan")
Form2.Show
Unload Me
Else
If Adodc1.Recordset.Fields("Jabatan") = "Admin" Then
Form2.cmd_barang.Enabled = False
Form2.cmd_datapel.Enabled = False
Form2.cmd_trans.Enabled = True
Form2.TxtUser.Text = Adodc1.Recordset.Fields("User_ID")
Form2.TxtNama.Text = Adodc1.Recordset.Fields("Nama")
Form2.TxtJabatan.Text = Adodc1.Recordset.Fields("Jabatan")
Form2.Show
Unload Me
End If
End If
End If
Adodc1.Refresh
If Adodc1.Recordset.EOF Then
MsgBox "Username/Password Salah", vbCritical, "Akses Ditolak"
Adodc1.Refresh
Text1.SetFocus
Else
If Adodc1.Recordset.Fields("Jabatan") = "Manager" Then
Form2.cmd_barang.Enabled = True
Form2.cmd_datapel.Enabled = True
Form2.cmd_trans.Enabled = True
Form2.TxtUser.Text = Adodc1.Recordset.Fields("User_ID")
Form2.TxtNama.Text = Adodc1.Recordset.Fields("Nama")
Form2.TxtJabatan.Text = Adodc1.Recordset.Fields("Jabatan")
Form2.Show
Unload Me
Else
If Adodc1.Recordset.Fields("Jabatan") = "Admin" Then
Form2.cmd_barang.Enabled = False
Form2.cmd_datapel.Enabled = False
Form2.cmd_trans.Enabled = True
Form2.TxtUser.Text = Adodc1.Recordset.Fields("User_ID")
Form2.TxtNama.Text = Adodc1.Recordset.Fields("Nama")
Form2.TxtJabatan.Text = Adodc1.Recordset.Fields("Jabatan")
Form2.Show
Unload Me
End If
End If
End If
4. Kodingan untuk Button Logout di Menu Utama.
D = MsgBox("Logout..?", vbYesNo + vbQuestion, "")
If D = vbYes Then
Form1.Show
Unload Me
End If
If D = vbYes Then
Form1.Show
Unload Me
End If
Demo Program :
0 Comment:
Post a Comment