Dim varmi As Boolean
Bu kod en üste eklenecek.Alttaki kodlarda userform içine.
Sub Admin()
MsgBox "Admin" 'Mesaj yerine admin icin gerekli kodlar yazilacak
End Sub
Sub user()
MsgBox "user" 'Mesaj yerine user icin gerekli kodlar yazilacak
End Sub
Function test(admin_User As String) As Boolean
Dim baglan As Object, rs As Object
Dim sorgu As String
varmi = False
Set baglan = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
baglan.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\Database.accdb;Persist Security Info=False;"
'--------------------------------------------------------------------------------------------------------------------------------------------------------
sorgu = "select * from [Users] where User_Name ='" & TextBox1.Value & "' and Password ='" & TextBox2.Value & "' and Role ='" & admin_User & "'"
rs.Open sorgu, baglan, 1, 1
If rs.RecordCount > 0 Then
varmi = True
If admin_User = "admin" Then
Call Admin: test = True
Else
Call user: test = True
End If
End If
rs.Close
baglan.Close
Set rs = Nothing
Set baglan = Nothing
End Function
Sub Label2_Click()
If test("admin") = True Then Exit Sub
If test("user") = True Then Exit Sub
If varmi = False Then MsgBox "Kullanici adi yada sifre yanlis..", vbCritical, "Hata"
End Sub