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 / November 2005

Tip: Looking for answers? Try searching our database.

Release Focus of Command Button

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LDMueller - 31 Oct 2005 17:16 GMT
We're using Word 2003.  I have a Userform with the following code:

Private Sub CommandButton1_Click()

   UserForm1.Hide

End Sub

Private Sub OptionButton1_Click()
 
   Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Count:=1, Name:=""
   Selection.Find.ClearFormatting
   With Selection.Find
       .Text = ""
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.MoveUp Unit:=wdLine, Count:=1

End Sub

Private Sub OptionButton2_Click()

   Selection.MoveDown Unit:=wdLine, Count:=1
   Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Count:=1, Name:=""
   Selection.Find.ClearFormatting
   With Selection.Find
       .Text = ""
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.MoveUp Unit:=wdLine, Count:=1
       
     
End Sub

The way it works is if a user select CommandButton2, it's suppose to go to
the end of the next page.  This part works fine.  My problem is that once a
user selects CommandButton2, it stays on that button so that it can't be
selected again and my user may need to select it several times before
locating the correct page.  No matter what I do, I can't release the focus
after it's selected so that it can be selected again.

I've tried working with setfocus and releasefocus, but haven't had any luck.

Can you assist me?

Thanks!
Tony Jollans - 31 Oct 2005 20:03 GMT
A slight correction: you are using *option* buttons not command buttons,
which does make a difference. Maybe you should be using command buttons but
that's a separate issue.

Your problem isn't focus so much as setting. Clicking a single ActiveX
option button makes it 'on' or 'true', and it may make other option buttons
false at the same time, but it doesn't automatically toggle it. If it is
already true, clicking it has no effect so you need to ensure it is false if
you want to give the user the option of clicking it a second time. At the
end of the click event procedure for optionbutton1, add this line:

Me.OptionButton1 = False

similarly, at the end of the optionbutton2 routine, add:

Me.OptionButton2 = False

--
Enjoy,
Tony

> We're using Word 2003.  I have a Userform with the following code:
>
[quoted text clipped - 57 lines]
>
> Thanks!
LDMueller - 01 Nov 2005 18:10 GMT
Tony,

This was exactly the code I needed.

Thank you very much!

> We're using Word 2003.  I have a Userform with the following code:
>
[quoted text clipped - 58 lines]
>
> Thanks!
Tony Jollans - 01 Nov 2005 19:24 GMT
My pleasure!

--
Enjoy,
Tony

> Tony,
>
[quoted text clipped - 63 lines]
> >
> > Thanks!

Rate this thread:






 
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.