+ Reply to Thread
Results 1 to 7 of 7

prevent user moving out of textbox if input is bad

  1. #1
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    473

    prevent user moving out of textbox if input is bad

    Hi,

    I'm looking for the answer to this please...

    I have a text box and I want it so that if the user has not typed in the number 1 then it won't let him leave the box.

    Can anyone tell me how to do this?

    Thanks

    John

  2. #2
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    What is your code so far ?

    Carim

  3. #3
    Forum Contributor spinkung's Avatar
    Join Date
    10-27-2006
    Posts
    199
    Hi,

    i recently used something like this....

    Please Login or Register  to view this content.
    guess you would have this...

    Please Login or Register  to view this content.
    HTH
    Spinkung.

  4. #4
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    473
    Hi, thanks for the quick reply..

    My code is

    Private Sub TextBox1_AfterUpdate()
    If TextBox1.Value <> "1" Then
    MsgBox "This should be 1"
    Me.TextBox1.SetFocus
    End If
    End Sub


    This code recognises that 1 hasn't been entered and returns the correct msgbox but it still jumps to the next box.

    Any ideas?

    Thanks

    John

  5. #5
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    Please Login or Register  to view this content.
    HTH
    Carim

  6. #6
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    473
    Thanks for the reply.

    I tried your method (I had to edit it to suit) but the msgbox keeps coming back up every time I cancel it and I have to close Excel to start working again.

    Thanks for your help but I think I am just going to leave it for now.

    Cheers

    John

  7. #7
    Registered User
    Join Date
    12-08-2006
    Posts
    4

    Data Validation

    Might it be easier to use a cell with data validation?

    You could select that the entry has to be a number, and use the 'equal to' and type the number 1, you could then tick the 'ignore blank' box which would prevent them moving from the cell till they had entered it, and you could use the 'Error Alert' tab to tell them they have to enter the number 1.

+ 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