Posted by : Miftahul Baihaqi Annazili March 10, 2016




Selamat datang kembali untuk teman-teman semua. Disini saya akan memberikan cara untuk membuat form login sederhana menggunakan vb 6 dengan database microsoft access 2010. Gambar - gambar diatas bisa teman-teman jadikan referensi tampilan yang akan dibuat.

Toolbox yang digunakan :
- Label
- TextBox
- Timer
- Frame
- Command Button
- Menu Editor

Berikut adalah source code untuk aplikasi tersebut : 

- Module1

Public con As New ADODB.Connection
Public rst As New ADODB.Recordset
Public strcon As String
Public strsql As String
Public Sub buka()
On Error GoTo pesan
strcon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & App.Path & "\buku.mdb;Persist Security Info=False"
If con.State = adStateOpen Then
con.Close
Set con = New ADODB.Connection
con.Open strcon
Else
con.Open strcon
End If
Exit Sub
pesan:
MsgBox "Tidak ada koneksi ke database..!", vbInformation, "Informasi"
End Sub

Public Sub tutup()
con.Close
End Sub

Form 1 (Menu Utama)

Private Sub Form_Load()
    LOGOUT.Visible = False
    DATA.Enabled = False
    PROSES.Enabled = False
    LAPORAN.Enabled = False
End Sub

Private Sub KELUAR_Click()
konfirmasi = MsgBox("Apakah Anda Yakin Ingin Keluar??? ", vbYesNo + vbInformation)
If konfirmasi = vbYes Then
End
End If
End Sub

Private Sub LOGIN_Click()
Form2.Show
End Sub

Private Sub LOGOUT_Click()
tutup
Form2.Show
Unload Me
End Sub

Private Sub Timer1_Timer()
Label3.Caption = Format(Now, "hh:mm:ss")
Label4.Caption = Format(Now, "dddd, d mmmm, yyyy")
End Sub

Form2 (Login)

Sub bersih()
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Command1_Click()
buka
Dim sql As String
Dim cari As New ADODB.Recordset
sql = "select * from TABEL_LOGIN where username ='" & LCase(Text1.Text) & "' and password =  '" & LCase(Text2.Text) & "'"
Set cari = con.Execute(sql)
If cari.EOF Then
   MsgBox "Maaf User atau Password anda salah !", vbInformation, "Informasi"
   Text1.SetFocus
   Call bersih
Else
    MsgBox "Anda berhasil login !", vbInformation, "Informasi"
    Dim akses As String
    Label3.Caption = cari!akses
    If Label3.Caption = "admin" Then
        Form1.LOGOUT.Visible = True
        Form1.LOGIN.Visible = False
        Form1.DATA.Enabled = True
        Form1.PROSES.Enabled = True
        Form1.LAPORAN.Enabled = True
        Form1.Show
        Unload Me
    ElseIf Label3.Caption = "user" Then
        Form1.LOGOUT.Visible = True
        Form1.LOGIN.Visible = False
        Form1.DATA.Enabled = False
        Form1.PROSES.Enabled = False
        Form1.LAPORAN.Enabled = True
        Form1.Show
        Unload Me
    End If
End If
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
Call bersih
End Sub

=================================================
Untuk Informasi Lebih Lanjut bisa menghubungi :
Email : javashare29@gmail.com
Facebook : Java Share
Twitter : @baihaqiannazili atau lewat kolom komentar dibawah ini.
>> Terima Kasih <<

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Java Sae - Hatsune Miku - Powered by Blogger - Designed by Johanes Djogan -