• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Help in Userform..!!

Rahul Aggarwal

New Member
Hello Team,

I have created a userform for login and password. below is the my code:

Private Sub CommandButton1_Click()
Dim username, Password As String

username = TextBox1.Text
Password = TextBox2.Text

If username = "myuser" And Password = "mypassword" Then
MsgBox "You entered the correct information", vbInformation
Unload Me 'unload this form

Else
MsgBox "You entered the wrong information", vbCritical
'now close the workbook
ActiveWorkbook.Close

End If
End Sub


I want different password for different username. for example if username is "Rahul" then password should be "Rahul" and if username is "Raghu" then password should be "Raghu"

Please help me how i can modify this coding to get desire result.
Your Response will greatly appreciate.
 
Code:
Private Sub CommandButton1_Click()
Dim username, Password As String
username = UserForm1.TextBox1.Text 'code amended
Password = UserForm1.TextBox2.Text 'code amended
If myuser = mypassword Then 'code amended
MsgBox "You entered the correct information", vbInformation
Unload Me 'unload this form
Else
MsgBox "You entered the wrong information", vbCritical
'now close the workbook
ActiveWorkbook.Close
End If
End Sub
 
Hi, Rahul Aggarwal!

If I don't understand wrong you want a list of user IDs and passwords, so you first has to build a 2 dimension array like:
Dim sUIDPwd(10, 2) as String
where you'll store in the 1st column the user ID and in the 2nd column the password. You could hardcode (not recommended) it within your code or you can load it from a range at any worksheet (in this case it'd be desirable to protect the worksheet and scramble the contents and... a lots of ands).

But regarding your comment about:
I want different password for different username. for example if username is "Rahul" then password should be "Rahul" and if username is "Raghu" then password should be "Raghu"
do you really mean that user ID and password are equal??? Besides insane it's a nonsense, IMHO.

Regards!
 
Back
Top