Consulting

Results 1 to 6 of 6

Thread: Solved: Better Code for Textbox

  1. #1

    Solved: Better Code for Textbox

    Hi,

    Please take a look at my userform, by clicking on the pencil icon. If you enter a number into the bottom right text box on the form it skips to where this row is located on the spreadsheet. But there are two problems.

    a) If you enter 0 by mistake - Runtime Error

    b) if you enter 1 > it picks up my column headings. And because of validation on the user form it brings up an error message (because text has been entered where numbers should be). This is annoying as if you want to find row number 100 you have to enter 1 first, therefore you always see this warning message.

    Would there not be a way around this by pressing return after entering a number in this textbox, instead of it automatically skipping to the row as you type the numbers in???

    Any help is much appreciated. Thanks

    password = pastille

  2. #2
    VBAX Regular
    Joined
    Apr 2008
    Posts
    7
    Location
    how about

    [vba]
    Private Sub txtRow_Change()
    If txtRow.Text = "" Then Exit Sub
    If txtRow.Text = "0" Then Exit Sub
    If txtRow.Text = "1" Then Exit Sub
    lCurrentRow = Val(txtRow.Text)
    Call UpdateDetails
    End Sub
    [/vba]

    Thats seems to work for me, i can still key in 100 and nothin, 0 or 1 just does nothing as it exits the sub.

  3. #3
    Works a dream. THanks

  4. #4
    VBAX Regular
    Joined
    Apr 2008
    Posts
    7
    Location
    No Worries

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    thomas, please mark your thread solved using the thread tools at the top of the page.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    VBAX Mentor tstav's Avatar
    Joined
    Feb 2008
    Location
    Athens
    Posts
    350
    Location
    Thomas,
    what happens if a space or any letter is entered in the txtRow textbox?

    I have attached a zip file where I have catered for:
    1. Valid row number entries
    2. Enable/disable the btnPrev, btnNext and btnSelectRecord buttons, depending on the selected record.
    3. Take into account the max row etc.

    I didn't have the time to go through all your code though.

    You can check the attachment anytime and use whatever you might find of interest to you.

    Regards, tstav
    He didn't know it was impossible, so he did it. (Jean Cocteau)

Posting Permissions

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