Login on VB

Blaze2002

New Member
Joined
Mar 2, 2004
Messages
13
Hiya evry1! rite i have a form in visual basics that i want to protect using a login thingie! i have 3 codes that work fine together:
Public declorations:

Dim x As String
Dim y As String
Dim loginsucceeded As Boolean

Cancel button:

Private Sub CommandButton1_Click()
If MsgBox(" Are you sure you want to cancel log in?", vbYesNo) = vbYes Then
End
End If
End Sub

and the login section:

Private Sub CommandButton2_Click()
x = "user"
y = "admin"
If txtpassword = y And txtusername = y Then
FRMwk1.Show
loginsucceeded = True
Unload Me
Else
If txtpassword = x And txtusername = x Then
FRMwk1.Show
loginsucceeded = True
Unload Me
Else
If loginsucceeded = False Then
MsgBox ("Please enter correct name and password")
End If
End If
End If
End Sub

This all works fine till i want to put in a password and username! :oops: where in the code can i tell VB what the password and username is and when i type it in how can i get it to show "******" instead of the letters??
:rolleyes:
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

DRJ

MrExcel MVP
Joined
Feb 17, 2002
Messages
3,853
Make a textbox on the userform. Look in the properties window for the PasswordChar field. Put a "*" in there with no quotes or whatever symbol you want to use.

Then try something like this

Dim MyPassword as String

MyPassword = "Admin123"


Then later on after the input say

If TextBox1.Value = MyPassword then

msgbox("Access Granted")

else

msgbox("Access Denied")

end if
 

Blaze2002

New Member
Joined
Mar 2, 2004
Messages
13
Nope it just didnt work! after every letter i typed it told me access was denied! :oops:
 

Marc

Active Member
Joined
Feb 21, 2002
Messages
388
Blaze, DRJ speaks the truth. Let's go through it:

You have a userform with 2 textboxes and 2 commandbuttons?

The textboxes are named: txtpassword and txtusername?

The commandbuttons are named: CommandButton1 and CommandButton2?

You have masked each textbox using DRJ's advice above?

The way your code is written you need to either type "user" or "admin" in both textboxes to gain access.
 

Blaze2002

New Member
Joined
Mar 2, 2004
Messages
13
yes i know! but it just wont do it! ive tried wot he said and what you said but with no luck! :(
 

vbsteve

Board Regular
Joined
Dec 11, 2003
Messages
99
Did you put the code supplied by DRJ in the txtpassword_change procedure??

if so then you need to move it to on of the command buttons (The one you have to press to login)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,964
Messages
5,599,069
Members
414,281
Latest member
Engjamal2021

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top