Release Focus of Command Button

L

LDMueller

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!
 
T

Tony Jollans

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top