View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Sam Kuo[_3_] Sam Kuo[_3_] is offline
external usenet poster
 
Posts: 86
Default SetFocus back to textbox after exiting

That's brilliant! Thanks for Mike.

"Dick Kusleika" wrote:

On Sun, 3 Aug 2008 13:54:00 -0700, Sam Kuo
wrote:

Hi Mike

Thanks for your reply.

I didn't use Cancel = True because it locks evertything else until the user
enters a value, but in my case, I'd like to allow the user to be able to go
away and look for the correct value if they have a false entry.

"Mike H" wrote:

Txt_StartValue.Value = ""
Cancel = True

"Sam Kuo" wrote:

Sub Txt_StartValue_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Dim Msg, Title, Response

If IsNumeric(Txt_StartValue.Value) = False Then
Msg = "You must enter a number"
Title = "Non-numeric Value"
Response = MsgBox(Msg,16,Title)
Txt_StartValue.SetFocus
End If

End Sub


If Len(Me.Txt_StartValue.Text) 0 And _
Not IsNumeric(Me.Txt_StartValue.Text) Then

This will allow the user to enter a number or a blank. Then you can use the
Cancel variable to keep it in the textbox, but allow the user to move out of
it if it's blank.

Another option is to set the focus elsewhere, then back to the box you
want.

Me.Txt_SomeOther.SetFocus
Me.Txt_StartValue.SetFocus

I've had some luck doing that.
--
Dick Kusleika
Microsoft MVP-Excel
http://www.dailydoseofexcel.com