Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
SetFocus not working
Hi,
I'm doing an invalid entry checking on a textbox, and in the event there's really an invalid entry, after the MsgBox popped up, I'd like the textbox to be get focus and its content highlighted. Everything runs fine except the SetFocus part. No VBA error, it's just that after the MsgBox, the focus is simply on the next control in my UserForm. The SetFocus seems to be doing nothing. Could someone help? code: -------------------------------------------------------------------------------- Private Sub tbxTotalStoresSales_AfterUpdate() If IsNumeric(ufInsertSales.tbxTotalStoresSales.Value) = False Then MsgBox "Invalid Entry! Numeric Values Only. Please try again.", _ vbOKOnly + vbExclamation, "Attention!" ufInsertSales.tbxTotalStoresSales.SetFocus ElseIf ufInsertSales.tbxTotalStoresSales.Value < 0 Then MsgBox "Invalid Entry! Negative Values Unacceptable. _ Please try again.", vbOKOnly + vbExclamation, "Attention!" ufInsertSales.tbxTotalStoresSales.SetFocus Else tbxTotalStoresSales.Value = FormatCurrency(tbxTotalStoresSales.Value) End If End Sub -------------------------------------------------------------------------------- Thank you, Henry T |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
SetFocus not working
Henry,
You can use the "BeforeUpdate" event which has a "Cancel" argument... '---------- Private Sub tbxTotalStoresSales_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) 'Test for non numeric entry. If IsNumeric(tbxTotalStoresSales.Value) = False Then tbxTotalStoresSales.Value = "Not a number" tbxTotalStoresSales.SelStart = 0 tbxTotalStoresSales.SelLength = 12 Cancel = True Else ... End if '---------- Regards, Jim Cone San Francisco, USA "Henry T" wrote in message ... Hi, I'm doing an invalid entry checking on a textbox, and in the event there's really an invalid entry, after the MsgBox popped up, I'd like the textbox to be get focus and its content highlighted. Everything runs fine except the SetFocus part. No VBA error, it's just that after the MsgBox, the focus is simply on the next control in my UserForm. The SetFocus seems to be doing nothing. Could someone help? code: -------------------------------------------------------------------------------- Private Sub tbxTotalStoresSales_AfterUpdate() If IsNumeric(ufInsertSales.tbxTotalStoresSales.Value) = False Then MsgBox "Invalid Entry! Numeric Values Only. Please try again.", _ vbOKOnly + vbExclamation, "Attention!" ufInsertSales.tbxTotalStoresSales.SetFocus ElseIf ufInsertSales.tbxTotalStoresSales.Value < 0 Then MsgBox "Invalid Entry! Negative Values Unacceptable. _ Please try again.", vbOKOnly + vbExclamation, "Attention!" ufInsertSales.tbxTotalStoresSales.SetFocus Else tbxTotalStoresSales.Value = FormatCurrency(tbxTotalStoresSales.Value) End If End Sub -------------------------------------------------------------------------------- Thank you, Henry T |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
SetFocus testing | Excel Programming | |||
Is this right? SetFocus weirdness | Excel Programming | |||
setfocus | Excel Programming | |||
SetFocus Question | Excel Programming | |||
SetFocus Problem | Excel Programming |