LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default change event; return focus to original textbox

I have a user form (i.e. frmGrade) that has a number of text boxes in
it (i.e. properties window/name = txtExpDesignA, txtExpDesignB,
txtExpDesignC...). The text boxes are set to 0 (i.e. properties winow/
value = 0) and the textboxes can take on a value between 0 and 5. I'm
using an event (for when the user switches text boxes to enter
additional information) to call a function that validates whether or
not the text box value is indeed between 0 and 5. If the value is NOT
between 0 and 5 then I want the program to "reselect" the textbox that
has the error in it.

For example, assume that the first text box is txtExpDesignA and when
you hit <tab the cursor moves to txtExpDesignB, and when you hit
<tab again the cursor moves you to txtExpDesignC, and so on.

If I enter 6 in txtExpDesignA (which is outside of the values 0 to 5)
and hit <tab the program will tell you that you entered an incorrect
value for txtExpDesignA. As a result, I want the cursor to stay in
txtExpDesignA and NOT move to txtExpDesignB on the change. In the
code below you will notice that I'm using
frmGrade.txtExpDesignA.SetFocus, but this does not seem to "reselect"
txtExpDesignA because the program just "tabs" to the next text box
(i.e. txtExpDesignB); however, if I use
frmGrade.txtExpDesignC.SetFocus, the program will skip over
txtExpDesignB and select txtExpDesignC just fine. Can someone clue me
in on how to "reselect" txtExpDesignA on the event.

An added question would be this: Is there a way to highlight all the
contents of the text box on using the .SetFocus method rather than
just moving the cursor? (i.e. if I do txtExpDesignC.SetFocus, the
cursor blinks at the end of the text...is there a way to have it
highlight the entire text just like the text is highlighted when you
hit <tab?)

Thanks in advance,

Matt

Option Explicit
Dim score As Boolean

Private Sub txtExpDesignA_AfterUpdate() 'Change
score = validate5(frmGrade.txtExpDesignA.Value)
If score = False Then
MsgBox ("You input an incorrect value in ""A.""" & Chr(13) _
& "The value must be a number and <= 5.")
'frmGrade.txtExpDesignC.SetFocus
frmGrade.txtExpDesignA.SetFocus
End If
End Sub

Private Function validate5(number) As Boolean
If (IsNumeric(number) = True) And (number <= 5) And (number 0) Then
validate5 = True
Else
validate5 = False
End If
End Function

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox.change event not firing! Craig M Excel Programming 0 October 3rd 06 04:30 AM
Is there a VBA Event to Detect Change in ActiveCell Focus? Larry A[_3_] Excel Programming 4 September 16th 05 03:23 AM
help with textbox change event N E Body Excel Programming 1 October 14th 04 10:07 PM
Textbox change event Ian Mangelsdorf Excel Programming 2 April 17th 04 09:30 AM
event which occurs when a TextBox receives focus Mikhail Excel Programming 2 October 7th 03 02:27 PM


All times are GMT +1. The time now is 07:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"