![]() |
Excel VBA - Cursor disappears when validating content of a TextBox
I ask you friend's help for this problem:
I designed a form with several TextBoxes, some of which I need to check to prevent input of invalid data, with some criteria I previously defined (for instance, input must be an integer, between 1 and 999, inclusive). Then, with the BeforeUpdate event, I display a MsgBox to alert user, and I want the focus to return to the TextBox with the invalid entry, in order to be changed to a valid one. My code worked fine except for a strange thing: cursor disappears when user clicks "Ok", and seems to be nowhere, as pressing Tab, Shift-Tab, Esc or Enter doesn't any effect. If user wants to start all up again, I must to make invisible the frame in which that TextBox is, but then VB returns an runtime error '-2147418113 (8000ffff)'. It seems that MSForms does something in those situations that takes the focus off any part of my application. I need somebody who understands it to explain it to me, please. Thank you all folks very much! My code is below. Private Sub TextBox_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) If IsNumeric(TextBox.Value) Then If CInt(TextBox.Value) < 1 Or CInt(TextBox.Value) 999 Then If MsgBox("Entry must be between 1 and 999. Click (OK) to enter new dara, or (Cancel) to clean form up and start again", vbOKCancel + vbExclamation, "Attention!") = vbCancel Then Cancel = False Frame1.Visible=False Else TextBox= "" TextBox.SetFocus Cancel = True Exit Sub End If End If Else BotCaixa = MsgBox("Entry must be an INTEGER, between 1 and 999.", vbOKOnly + vbExclamation, "Attention!") TextBox = "" TextBox.SetFocus Cancel = True End If End Sub --- Message posted from http://www.ExcelForum.com/ |
All times are GMT +1. The time now is 12:04 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com