Private Sub LoginMasuk_Click()
Dim Password As String
Dim Level As String
Dim pass As String
pass = MD5(TextBox2.Value)
Set WsUserName = Sheets("Data")
Set RgUserPas = WsUserName.Range("A2:A20")
Set c = RgUserPas.Find(TextBox1.Value, LookIn:=xlValues, MatchCase:=False)
Password = c.Offset(0, 1).Value
Level = c.Offset(0, 2).Value
If pass <> Password Then
MsgBox "password yang anda masukan salah", vbCritical, "User Login"
Exit SubElse
If Level = "Admin" Then
MsgBox "Selamat Datang " & TextBox1.text, vbInformation, "Message"
'MsgBox "Anda Login Sebagai " & Level, vbInformation, "User Login"
loginApp.Hide
Sheets("Data").Visible = xlSheetVisible
Sheets("Hai").Visible = xlSheetVisible
Sheets("Halo").Visible = xlSheetVisible
Menu_Admin.Label1.Caption = Level
Menu_Admin.Show
Call bersih
Exit Sub
ElseIf Level = "Siswa" Then
MsgBox "Selamat Datang " & TextBox1.text, vbInformation, "Message"
'MsgBox "Anda Login Sebagai " & Level, vbInformation, "User Login"
loginApp.Hide
Sheets("Data").Visible = xlSheetVeryHidden
'Sheets("Data").Visible = xlSheetVisible
Sheets("Hai").Visible = xlSheetVisible
Sheets("Halo").Visible = xlSheetVisible
Menu_Siswa.Label1.Caption = Level
Menu_Siswa.Show
Call bersih
Exit Sub
End If
End If
End Sub
我在代码中遇到错误->
Password = c.Offset(0, 1).Value
我如何解决
答案 0 :(得分:1)
检查您的.Find
呼叫是否真的首先找到了东西。将其放在该行之前:
If c Is Nothing Then
Msgbox "'" & TextBox1.Value & "' was not found"
Exit Sub
End If