I have created a workbook that should only be accessed by a couple of people. The below code has been placed in the workbook. There is a userform
with two textboxes
, one used for username and one used for password.
I then check those entries against entries I have created in VBA. however, It work's for one person but not the other.
RossName and Ross password allow me access to the workbook, however the GulsenName and GulsenPassword does not. It will return the "ELSE"
function and show the MsgBox, so be false? what am I missing? Thankyou for your help.
Private Sub CommandButton2_Click()
Dim enteredUserName As String
Dim GulsenName As String
Dim RossName As String
Dim enteredpassword As String
Dim gulsenPassword As String
Dim RossPassword As String
RossName = "RossA"
RossPassword = "Password1"
GulsenName = "Gulsen"
gulsenPassword = "Password2"
enteredUserName = Me.TextBox1.Text
enteredpassword = Me.TextBox2.Text
If (enteredUserName = RossName Or enteredpassword = GulsenName) And (enteredpassword = RossPassword Or enteredpassword = gulsenPassword) Then
Worksheets(1).Select
Unload Me
Else
MsgBox ("userName or Password incorrect, please try again")
End If
End Sub
Change AND to OR
Private Sub CommandButton2_Click()
Dim enteredUserName As String
Dim GulsenName As String
Dim RossName As String
Dim enteredpassword As String
Dim gulsenPassword As String
Dim RossPassword As String
RossName = "RossA"
RossPassword = "Password1"
GulsenName = "Gulsen"
gulsenPassword = "Password2"
enteredUserName = Me.TextBox1.Text
enteredpassword = Me.TextBox2.Text
If (enteredUserName = RossName And enteredpassword = RossPassword) Or (enteredUserName = GulsenName And enteredpassword = gulsenPassword) Then
Worksheets(1).Select
Unload Me
Else
MsgBox ("userName or Password incorrect, please try again")
End If
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.