Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default How do I set focus

Hi,

I have a userform with a textbox and the following in the AfterUpdate event:

If Not IsNumeric(Me.txtBill.Value) Then
MsgBox "This needs to be a number", vbExclamation, "Input Error"
Me.txtBill.Value = ""
Me.txtBill.SetFocus

However this does not set the focus back to the txtBill

What am I doing wrong?
Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default How do I set focus

Thanks - works a treat!
"Beto" wrote in message
...
Newbie wrote:

Hi,

I have a userform with a textbox and the following in the AfterUpdate

event:

If Not IsNumeric(Me.txtBill.Value) Then
MsgBox "This needs to be a number", vbExclamation, "Input Error"
Me.txtBill.Value = ""
Me.txtBill.SetFocus

However this does not set the focus back to the txtBill


You should put your code in the BeforeUpdate event and set Cancel to
TRUE if the condition of exit is not met.

Ex:

Private Sub txtBill_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(Me.txtBill.Value) Then
MsgBox "This needs to be a number", vbExclamation, "Input Error"
Me.txtBill.Value = ""
Cancel = True
End If
End Sub

Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default How do I set focus

Newbie wrote:

Hi,

I have a userform with a textbox and the following in the AfterUpdate event:

If Not IsNumeric(Me.txtBill.Value) Then
MsgBox "This needs to be a number", vbExclamation, "Input Error"
Me.txtBill.Value = ""
Me.txtBill.SetFocus

However this does not set the focus back to the txtBill


You should put your code in the BeforeUpdate event and set Cancel to
TRUE if the condition of exit is not met.

Ex:

Private Sub txtBill_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(Me.txtBill.Value) Then
MsgBox "This needs to be a number", vbExclamation, "Input Error"
Me.txtBill.Value = ""
Cancel = True
End If
End Sub

Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.

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
COMBO BOX FOCUS -debi- Excel Worksheet Functions 0 July 18th 08 03:07 PM
focus Capp Excel Discussion (Misc queries) 2 November 18th 05 07:25 PM
set focus tkaplan Excel Discussion (Misc queries) 3 September 27th 05 07:41 PM
Focus David Unger Excel Worksheet Functions 20 March 21st 05 06:43 PM
set focus RickK Excel Programming 1 October 10th 03 12:27 PM


All times are GMT +1. The time now is 07:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"