PDA

View Full Version : Solved: Better Code for Textbox



thomas.szwed
04-18-2008, 03:12 AM
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

lockma
04-18-2008, 03:54 AM
how about


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


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.

thomas.szwed
04-18-2008, 07:35 AM
Works a dream. THanks

lockma
04-18-2008, 07:37 AM
No Worries

lucas
04-18-2008, 09:07 AM
thomas, please mark your thread solved using the thread tools at the top of the page.

tstav
04-18-2008, 10:59 AM
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