Options buttons in a frame

J

JK

Hello.
I have a word letter *.dot, wjith some bookmarks. One bookmark is called
frametest, and on the UserForm I have a frame with three option buttons. The
frame is called Frame1, option buttons are called option 1, 2 and three.
I want the bookmark in the letter to get the choice from the frame, and the
option the user have pusched.
Options are : Januar Februar Mars.
Have anyone a solution.

Thanks...
 
J

Jonathan West

JK said:
Hello.
I have a word letter *.dot, wjith some bookmarks. One bookmark is called
frametest, and on the UserForm I have a frame with three option buttons. The
frame is called Frame1, option buttons are called option 1, 2 and three.
I want the bookmark in the letter to get the choice from the frame, and the
option the user have pusched.
Options are : Januar Februar Mars.
Have anyone a solution.

Create a bookmark called "Month" where yu want the text to go. Then use this
code to put the appropriate month there.

If Januar.Value Then
ActiveDocument.Bookmark("Month").Range.Text = "Januar"
ElseIf Februar.Value Then
ActiveDocument.Bookmark("Month").Range.Text = "Februar"
Else
ActiveDocument.Bookmark("Month").Range.Text = "Mars"
End If
 
D

Doug Robbins - Word MVP

Hi JK,

Use:

Dim acontrol As Control, i As Long, strmonth As String
For i = 1 To 3
Set acontrol = Frame1.Controls(i - 1)
If acontrol.Value = True Then
Exit For
End If
Next i
Select Case i
Case 1
strmonth = "Januar"
Case 2
strmonth = "februar"
Case Else
strmonth = "Mars"
End Select
ActiveDocument.Bookmarks("frametest").Range.InsertBefore strmonth

Probably a simpler to use a combobox (cmbMonth) containing the months. Then
all you would need is

If cmbMonth.ListIndex >= 0 Then
ActiveDocument.Bookmarks("frametest").Range.InsertBefore cmbMonth
Else
MsgBox "Please select a month."
End if

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
H

Harold

Try this:
Private Sub optFeb_Click()
'test if the option button is checked
If optFeb.Value = True Then
SetBookmark "February"
End If
End Sub

Private Sub optJan_Click()
'test if the option button is checked
If optJan.Value = True Then
SetBookmark "January"
End If
End Sub

Private Sub optMar_Click()
'test if the option button is checked
If optMar.Value = True Then
SetBookmark "March"
End If

End Sub

Sub SetBookmark(strMonth As String)
'select the bookmark,
'delete the range of the selection
'pass the appropriate value to the selection range
'reset the bookmark since it will be deleted when the text is added
ActiveDocument.Bookmarks("FrameTest").Range.Select
With Selection
.Range.Delete
.Text = strMonth
.Bookmarks.Add "FrameTest"
End With

End Sub
The document will be updated when the form closes.

Regards,
 

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