Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Using SetFocus with Frames

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jimec74 - 19 May 2008 07:02 GMT
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
jimec74 - 20 May 2008 08:09 GMT
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

> Hi
>
[quoted text clipped - 26 lines]
>
> James
Peter T - 20 May 2008 09:41 GMT
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

> It's OK - I solved my own problem with the _Exit(ByVal Cancel ...) event!!
> (do a search on "SetFocus")
[quoted text clipped - 34 lines]
> >
> > James
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.