+ Reply to Thread
Results 1 to 2 of 2

Limiting input with input box

  1. #1
    Registered User
    Join Date
    06-26-2005
    Posts
    10

    Limiting input with input box

    Hi I'm doing a school project and I'm trying to find a way to limit what the user enters into the input box...for example,

    Sub Log_On()
    Dim bText As String
    ' here is the INPUTBOX-function :
    bText = InputBox("Please Type Your Name", "Username")
    ' here is the INPUTBOX-method :
    bText = Application.InputBox("Please Enter Your Password", "Password")
    MsgBox "You typed the following password:" & Chr(13) & _
    bText & Chr(13), , "Login Details"
    Sheets("Hardware").Select
    End Sub

    Therefore, I want to limit the user to be only allowed to enter ''abc" into the password field.. How can I tweak my formula to allow me to do that? Also, if teh user types in teh wrong password, I don't want the macro to take him to the 'Hardware' sheet, I want it to stay in teh same sheet.

    Thanks a lot..

  2. #2
    Dave Peterson
    Guest

    Re: Limiting input with input box

    Usually when you're checking passwords, you want the user to type whatever they
    want--but you want to verify it before your code does something for them.

    Sub Log_On()

    Dim UserNameText As String
    dim PWDText as string
    Dim RealPWD as string

    RealPWD = "abc"

    UserNameText = InputBox("Please Type Your Name", "Username")

    PWDText = Application.InputBox("Please Enter Your Password", "Password")

    MsgBox "You typed the following password:" & Chr(13) & _
    PWDText & Chr(13), , "Login Details"

    if pwdtext <> realpwd then
    msgbox "no, no, no!
    else
    Sheets("Hardware").Select
    end if

    End Sub

    Be aware that this kind of stuff in excel is very simple to overcome by anyone
    who is really interested.

    petros89 wrote:
    >
    > Hi I'm doing a school project and I'm trying to find a way to limit what
    > the user enters into the input box...for example,
    >
    > Sub Log_On()
    > Dim bText As String
    > ' here is the INPUTBOX-function :
    > bText = InputBox("Please Type Your Name", "Username")
    > ' here is the INPUTBOX-method :
    > bText = Application.InputBox("Please Enter Your Password",
    > "Password")
    > MsgBox "You typed the following password:" & Chr(13) & _
    > bText & Chr(13), , "Login Details"
    > Sheets("Hardware").Select
    > End Sub
    >
    > Therefore, I want to limit the user to be only allowed to enter ''abc"
    > into the password field.. How can I tweak my formula to allow me to do
    > that? Also, if teh user types in teh wrong password, I don't want the
    > macro to take him to the 'Hardware' sheet, I want it to stay in teh
    > same sheet.
    >
    > Thanks a lot..
    >
    > --
    > petros89
    > ------------------------------------------------------------------------
    > petros89's Profile: http://www.excelforum.com/member.php...o&userid=24645
    > View this thread: http://www.excelforum.com/showthread...hreadid=492518


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1