Password on forms

  • Thread starter Thread starter Cesar
  • Start date Start date
C

Cesar

Hi,
I'm using a form (frmEntryCost) to enter values to Cells in a Worksheet,
but before open this form I need to prompt for a password and if this
password is valid, then open the entry form if not, a message should show
with "wrong password, try again!" and keep asking for the password until it
matches the valid password. The real password I want it to be, let's say in
the cell Z1, where I can change it easily. What is the code for this password
to work?
Thanks
 
Thanks Rylo,

Where in the code, do I open or make my form (frmEntryCost) visible?
 
This is a sample of using Userform. first create two Userforms. then,
put two commandbutttons, one for Enter, the other for Cancel, and one
Label for Warning and one textbox for password input in Userform1. I put
password in the code instead of cell for simplicity. Run the macro Testform.

'put the macro Testform in standard module
Sub Testform()
UserForm1.Show
End Sub

'put the code below in Userform1
Const password = "pass" '<<==Change to your Password

Private Sub UserForm_Initialize()
Me.TextBox1.PasswordChar = "*"
Me.Label1.Visible = False
Me.Label1.Caption = "Wrong Password, try again!"
End Sub

Private Sub CommandButton1_Click() '<<==For Enter
If Me.TextBox1.Value = password Then
Unload UserForm1
UserForm2.Show
Else
Me.TextBox1.SetFocus
Me.TextBox1.Value = ""
Me.Label1.Visible = True
End If
End Sub

Private Sub CommandButton2_Click() '<<==For Cancel
Unload UserForm1
End Sub

keiji
 
Thanks, both worked perfect!
I tried both and both works perfect, I like the one with the forms!
 
Thanks Keiji,
Just one more question,
Where do I need to write the code?
Const password ="pass"
you said below in UserForm1, but I don't know where, under click() or
activate() or where?

Thanks again
 
at the top part of Userform1's code module where you write the event
procedures. i mean putting it before any sub procedures or functions in
the code module(userform1).

keiji
 
at the top part of Userform1's code module where you write the event
procedures. i mean putting it before any sub procedures or functions in
the code module(userform1).

keiji
 
at the top part of Userform1's code module where you write the event
procedures. i mean putting it before any sub procedures or functions in
the code module(userform1).

keiji
 
at the top part of Userform1's code module where you write the event
procedures. i mean putting it before any sub procedures or functions in
the code module(userform1).

keiji
 
at the top part of Userform1's code module where you write the event
procedures. i mean putting it before any sub procedures or functions in
the code module(userform1).

keiji
 
at the top part of Userform1's code module where you write the event
procedures. i mean putting it before any sub procedures or functions in
the code module(userform1).

keiji
 
Sorry for so many replys. my newsreader seems to have got some trouble.
 
Glad to hear my poor explanation(and bad English) has made sense for you.

Keiji
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top