User Login Form

Source For User Login

Dim Cnn As ADODB.Connection
Dim rs As ADODB.Recordset

Private Sub CmdBatal_Click()
Unload Me
End Sub

Private Sub CmdMasuk_Click()
Call CekPassword
End Sub

Private Sub Form_Activate()
Text1.SetFocus
End Sub

Private Sub Form_Load()

'Membuat Sebuah Koneksi
Set Cnn = New ADODB.Connection

With Cnn
.ConnectionString = "provider=SQLOLEDB;" & _
"Data Source=10.11.12.56,1433/Kenari;initial Catalog=Pulsa;" & _
"Trusted Connection=yes; User ID=pulsa; Password=Pulsa123"
.Open
End With

'Atur Letak Form
Me.Top = (Main.ScaleHeight - Me.ScaleHeight) / 2
Me.Left = (Main.ScaleWidth - Me.ScaleWidth) / 2

End Sub

Private Sub Form_Unload(Cancel As Integer)
Cnn.Close

Set Cnn = Nothing
Set Comm = Nothing
Set rs = Nothing


End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
End If
End Sub

Sub CekPassword()

Dim SintakSQL As String

'Mencari data pengguna atau Pengguna pada tabel
SintakSQL = " Select * From members " & _
" Where member='" & Text1.Text & "'"

Set rs = Cnn.Execute(SintakSQL)

'Jika Pengguna Id Ada
If rs.EOF Then
'Cek Password dari Pengguna ID
MsgBox "User ID tidak terdaftar", vbOKOnly + vbExclamation, "Salah User ID"
'Jika Data Pengguna ditemukan
Text1.Text = ""
Text1.SetFocus
Exit Sub
Else
If rs.Fields("sandi") <> Text2.Text Then
MsgBox "Password Anda Salah", vbOKOnly + vbExclamation, "Salah Password"
Text2.Text = ""
Text2.SetFocus
Exit Sub
Else
'ambil rs userid di db, simpan ke namauser di variabel public
namauser = rs("member")

'Membaca Hak Akses dari tiap menu
'Membaca Hak Akses dari Menu Master
If rs.Fields("m1") = "1" Then
Menu1 = True
Else
Menu1 = False
End If
'Membaca Hak Akses dari Menu Pengaturan
If rs.Fields("m2") = "1" Then
Menu2 = True
Else
Menu2 = False
End If
'Membaca Hak Akses dari Menu Bantuan
If rs.Fields("m3") = "1" Then
Menu3 = True
Else
Menu3 = False
End If

'Menampilkan Menu
Call Menu_Tampak
With Main

.MnuFile(1).Enabled = False
.MnuFile(2).Enabled = True
.MnuFile(4).Enabled = False

End With
End If
End If

rs.Close

actifitas = Replace(SintakSQL, "'", "`", 1, -1)
SintakSQL = " insert into Activity (sandi, activity) values ('" & namauser & "','" & actifitas & "')"
Cnn.Execute (SintakSQL)

Unload Me
End Sub

Read Users' Comments (0)

0 Response to "User Login Form"