我按照this guide,結果發現,如果我的用戶名和密碼都錯了,它會拋出一個運行時錯誤:多用戶登錄表單
"6" Overflow error.
不過,我已經使用下面的代碼嘗試:
ElseIf Username <> u And Password <> p Then
MsgBox "Username & Password not matched", vbCritical + vbOKCancel
Exit Do
我試過使用此代碼,但即使我的用戶名和密碼匹配它仍然會拋出下面的MsgBox。
這裏
Private Sub LoginButton_Click()
Application.ScreenUpdating = False
Dim Username As String
Dim Password As String
Dim i As Integer
Dim j As Integer
Dim u As String
Dim p As String
If Trim(TextBox1.Text) = "" And Trim(TextBox2.Text) = "" Then
MsgBox "Enter username and password.", vbOKOnly
ElseIf Trim(TextBox1.Text) = "" Then
MsgBox "Enter the username ", vbOKOnly
ElseIf Trim(TextBox2.Text) = "" Then
MsgBox "Enter the Password ", vbOKOnly
Else
Username = Trim(TextBox1.Text)
Password = Trim(TextBox2.Text)
i = 1
Do While Cells(1, 1).Value <> ""
j = 1
u = Cells(i, j).Value
j = j + 1
p = Cells(i, j).Value
If Username = u And Password = p And Cells(i, 3).Value = "fail" Then
MsgBox "Your Account temporarily locked", vbCritical
Exit Do
ElseIf Username = u And Password = p Then
Call clr
'LoginFlag = True
Unload Me
MsgBox ("Welcome " + u + ", :)")
Exit Do
ElseIf Username <> u And Password = p Then
MsgBox "Username not matched", vbCritical + vbOKCancel
Exit Do
ElseIf Username = u And Password <> p Then
If Cells(i, 3).Value = "fail" Then
MsgBox "Your account is blocked", vbCritical + vbOKCancel
Exit Do
ElseIf Cells(i, 4).Value < 2 Then
MsgBox "Invalid password", vbCritical
Cells(i, 4).Value = Cells(i, 4) + 1
Exit Do
Else
Cells(i, 4).Value = Cells(i, 4) + 1
Cells(i, 3).Value = "fail"
'Cells(i, 2).Value = ""
Cells(i, 2).Interior.ColorIndex = 3
Exit Do
End If
ElseIf Username <> u And Password <> p Then
MsgBox "Username & Password not match", vbCritical + vbOKCancel
Exit Do
Else
i = i + 1
End If
Loop
End If
Application.ScreenUpdating = True
End Sub
請下次使用「代碼格式化按鈕」{}'來格式化您的代碼!另外,請通過添加錯誤消息的*文本*來改進您的問題,而不僅僅是截圖。此外,如果有東西說「在這裏輸入圖像說明」,*請輸入圖像說明*。要問一個正確的問題真的不是那麼難! –
另請注意,這是密碼對話框最糟糕的例子。密碼是其保護的未加密數據的一部分。從來沒有想過使用這樣的東西! –
沒有看到你的代碼我不能確定 - 但我的猜測是你有3條線你已經在循環內顯示我們。因此,只要您點擊不是您正在查找的用戶名**和**密碼不是您正在查找的那個,就會顯示該消息。 – YowE3K