UserForm.

Nigel Martin

Board Regular
Joined
Feb 17, 2002
Messages
133
I am a total novice concerning UserForms. I have managed to design the form it has 1 TextBox and 2 buttons on it. I want users to input a password into the TextBox and then press 1 of the buttons marked "OK" to then opperate a macro or if they press the other button marked "Cancel" to make the UserForm disappear. Help !
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Im Just learning myself, This came out of one of my lesson books, Hope it helps



Private Sub cmdValid_Click()
'This procedure checks the input password
Dim Response As Integer
If txtPassword.Text = txtPassword.Tag Then
'If correct, display message box
MsgBox "You've passed security!", vbOKOnly + vbExclamation, "Access Granted"
Else
'If incorrect, give option to try again
Response = MsgBox("Incorrect password", vbRetryCancel + vbCritical, "Access Denied")
If Response = vbRetry Then
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
Else
End
End If
End If
txtPassword.SetFocus
End Sub
 
Upvote 0
Double click on the "OK" button and this will throw up code that looks like this:

<pre>
Private Sub CommandButton1_Click()

End Sub</pre>

Between these two lines put in the name of your macro. e.g. if I wanted to run a macro called "MyMacro" my code would look like this:

<pre>
Private Sub CommandButton1_Click()
MyMacro
End Sub</pre>

Go back to your userform view and double click on the "Cancel" button, put this code in:

<pre>
Unload Me</pre>

HTH
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,177
Members
448,554
Latest member
Gleisner2

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
Back
Top