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 / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

Active location on UserForm following MsgBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Starbird - 11 Feb 2005 02:01 GMT
I'm sure this is a very simple thing, but I can't seem to make it happen.
I have the following code:

If me.txtAuth = " " Then
 MsgBox ("Enter Author")
 Me.Show
End If

I wanted the text box txtAuth to be the active location when user selects OK
in msgbox, how do I do that?

Thanks!
Jay Freedman - 11 Feb 2005 03:26 GMT
>I'm sure this is a very simple thing, but I can't seem to make it happen.
>I have the following code:
[quoted text clipped - 8 lines]
>
>Thanks!

You definitely don't want Me.Show, since the userform (Me) is already
shown.

Instead, use txtAuth.SetFocus to move the cursor back to the textbox.
(Note that the use of Me to refer to controls on the current userform
is optional.)

There are a couple of ways to do this validation, depending on what
effect you want to achieve. Using SetFocus this way is good if you do
all the validation for several-to-many controls all at once when the
user clicks the OK button. Whichever control fails validation, set the
focus to that control.

The other way is to write code in the Exit procedure of each
data-entry control. That procedure comes with a Cancel argument; if
the contents fail validation, you set Cancel = True and the cursor
won't leave the control. Like this:

Private Sub txtAuth_Exit(ByVal Cancel As MSForms.ReturnBoolean)
   If txtAuth.Text = "" Then
       MsgBox "Enter Author"
       Cancel = True
   End If
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org
Starbird - 11 Feb 2005 03:49 GMT
Thanks Jay, this group has been so helpful to me in this project I took on.
I could have never done it without all the help from this group!
Thanks again!

> >I'm sure this is a very simple thing, but I can't seem to make it happen.
> >I have the following code:
[quoted text clipped - 38 lines]
> Jay Freedman
> Microsoft Word MVP         FAQ: http://word.mvps.org
 
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.