Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using SetFocus with Frames

Hi

I have a UserForm with several text boxes embedded into frames (used only as
a visual aid for grouping the text boxes).

I am using AfterUpdate to validate the user input, eg:

'---------------------------------------
Sub Txt_StartValue_AfterUpdate()

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
'-----------------------------------------

Problem is, when Txt_StartValue is embedded within a Frame, the SetFocus
doesn't work & the next textbox is selected.

Any ideas as to how to get the correct textbox selected via the SetFocus?

Thanks,

James
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using SetFocus with Frames

It's OK - I solved my own problem with the _Exit(ByVal Cancel ...) event!!
(do a search on "SetFocus")

Thanks anyway to anyone who thought about this.... seems to me like there's
a bug with SetFocus?

James

"jimec74" wrote:

Hi

I have a UserForm with several text boxes embedded into frames (used only as
a visual aid for grouping the text boxes).

I am using AfterUpdate to validate the user input, eg:

'---------------------------------------
Sub Txt_StartValue_AfterUpdate()

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
'-----------------------------------------

Problem is, when Txt_StartValue is embedded within a Frame, the SetFocus
doesn't work & the next textbox is selected.

Any ideas as to how to get the correct textbox selected via the SetFocus?

Thanks,

James

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Using SetFocus with Frames

The reason SetFocus 'apparently' fails to work in the AfterUpdate event is
while that event is being processed focus remains in that textbox. It's only
after the update event has completed focus Exits.

VBA textboxes do not have a purpose made Validate event, like VB6 forms, so
the Exit event is probably what you need. However the Exit event might do
more than you want; if say user is tabbing around controls without changing
anything your Exit event will fire when leaving an unchanged empty textbox.
Depending on your needs you might want to add If Len(the text) 0 then etc.

Regards,
Peter T

"jimec74" wrote in message
...
It's OK - I solved my own problem with the _Exit(ByVal Cancel ...) event!!
(do a search on "SetFocus")

Thanks anyway to anyone who thought about this.... seems to me like

there's
a bug with SetFocus?

James

"jimec74" wrote:

Hi

I have a UserForm with several text boxes embedded into frames (used

only as
a visual aid for grouping the text boxes).

I am using AfterUpdate to validate the user input, eg:

'---------------------------------------
Sub Txt_StartValue_AfterUpdate()

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
'-----------------------------------------

Problem is, when Txt_StartValue is embedded within a Frame, the SetFocus
doesn't work & the next textbox is selected.

Any ideas as to how to get the correct textbox selected via the

SetFocus?

Thanks,

James



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
How do I subtract time where hh:mm:ss:ff (frames = 30 frames/sec) KJ7 Excel Discussion (Misc queries) 14 December 3rd 16 10:03 AM
Frames and buttons Sally Mae Excel Programming 1 July 5th 06 02:19 AM
freezing frames Bob Griendling Excel Worksheet Functions 4 July 1st 06 10:58 PM
group/frames libby Excel Programming 2 April 1st 04 01:47 PM
Forms and Frames Shunt Excel Programming 5 August 1st 03 12:28 AM


All times are GMT +1. The time now is 12:55 PM.

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"