Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default TextBox Focus And Active Cursor Movement In User Forms

I have a user form with many text boxes, most of which I edit for validity.
If someone enters an invalid number, all I want to do is MsgBox them, clear
the textbox, and return the blinking cursor to that same textbox... well, I
have tried everything. I can clear the textbox, but I still have to use my
mouse to get back to that textbox. I have used the SetFocus, keybd_event to
tab backwards, and other tricks, none of which completely worked. Ideas?
--
Rich Locus
Logicwurks, LLC
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default TextBox Focus And Active Cursor Movement In User Forms

---Why dont you try using the Exit event of the Textbox for
validations...Cancel ...

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

'If validations fail
Cancel = True
End Sub


---If you are validating it from command button...what happens when you
setfocus and ExitSub

TextBox3.SetFocus: Exit Sub

If this post helps click Yes
---------------
Jacob Skaria


"Rich Locus" wrote:

I have a user form with many text boxes, most of which I edit for validity.
If someone enters an invalid number, all I want to do is MsgBox them, clear
the textbox, and return the blinking cursor to that same textbox... well, I
have tried everything. I can clear the textbox, but I still have to use my
mouse to get back to that textbox. I have used the SetFocus, keybd_event to
tab backwards, and other tricks, none of which completely worked. Ideas?
--
Rich Locus
Logicwurks, LLC

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default TextBox Focus And Active Cursor Movement In User Forms

Jacob:

Your solution works VERY WELL!! The only downside that if I use "MsgBox" to
display the error, then after the message, the cursor is no longer in the
textbox and I have to click it.

HOWEVER, if I render the error message ON THE FORM, and not use MsgBox, it's
a perfect solution.

Thanks again for your time!

Here's the final code based on your suggestion:

Private Sub txtTotalUnits_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(txtTotalUnits) Then
Me.txtTotalUnits = vbNullString
Me.txtErrorMessage.Value = "Total Units Must Be Numeric"
Cancel = True
End If
End Sub

Rich Locus
Logicwurks, LLC


"Jacob Skaria" wrote:

---Why dont you try using the Exit event of the Textbox for
validations...Cancel ...

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

'If validations fail
Cancel = True
End Sub


---If you are validating it from command button...what happens when you
setfocus and ExitSub

TextBox3.SetFocus: Exit Sub

If this post helps click Yes
---------------
Jacob Skaria


"Rich Locus" wrote:

I have a user form with many text boxes, most of which I edit for validity.
If someone enters an invalid number, all I want to do is MsgBox them, clear
the textbox, and return the blinking cursor to that same textbox... well, I
have tried everything. I can clear the textbox, but I still have to use my
mouse to get back to that textbox. I have used the SetFocus, keybd_event to
tab backwards, and other tricks, none of which completely worked. Ideas?
--
Rich Locus
Logicwurks, LLC

Reply
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
Movement of the cursor tran1728 Excel Discussion (Misc queries) 4 May 8th 10 05:28 AM
Cursor movement pfk5971 Excel Discussion (Misc queries) 1 July 12th 09 12:03 AM
Cursor Movement Froggy2899 Excel Discussion (Misc queries) 2 August 11th 08 10:54 PM
cursor movement Paulo Couto Excel Discussion (Misc queries) 5 October 25th 07 11:32 PM
Cursor movement Tedebare Excel Programming 2 March 15th 07 06:29 PM


All times are GMT +1. The time now is 09:50 AM.

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"