View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default 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