Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: UserForm.

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Posts
    133
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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 !

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    Arkansas
    Posts
    358
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  3. #3
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Double click on the "OK" button and this will throw up code that looks like this:


    Private Sub CommandButton1_Click()

    End Sub


    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:


    Private Sub CommandButton1_Click()
    MyMacro
    End Sub


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


    Unload Me


    HTH

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •