Problem checking radio button state and running autotext macro

C

charlie6067

I've designed a user form that's a mixture of checkboxes and one set
of radio buttons. When the OK button is clicked, each checkbox runs a
macro that inserts a stored autotext entry at a bookmark - that works
great. I want the same action for a group of radio buttons (tbut the
coding method must be different as I'm having problems. Here's the
code for the OK button. Please show me the coding errors. Thanks,
Charlie charlie6067

On of the checkboxes is named optTX.
Autotext entry = TXAdd

Private Sub optTX_Click()
End Sub

Private Sub cmdOK_Click()
' OK Button

If optTX.Value = True Then
' Call TXAdd autotext address for TX

PasswordOff
Application.DisplayAutoCompleteTips = False
With AutoCorrect
.CorrectInitialCaps = True
.CorrectSentenceCaps = True
.CorrectDays = True
.CorrectCapsLock = True
.ReplaceText = True
End With

Selection.GoTo What:=wdGoToBookmark, Name:="bmkALTAddress"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = True
End With

ActiveDocument.AttachedTemplate.AutoTextEntries("TXAdd"). _
Insert Selection.Range, RichText:=True

PasswordOn

End If
End Sub
 
G

Greg Maxey

Charlie,

I don't know about some of your code (seems irrevelent to the issue)
but something like this should do:

I created three option buttons OB1, OB2 and OB3 and three autotext
entries opt1 opt2 and opt3

Private Sub cmdOK_Click()
Dim oRng As Word.Range
Dim oBKMs As Bookmarks
Dim oAT As AutoTextEntries
Set oBKMs = ActiveDocument.Bookmarks
Set oAT = ActiveDocument.AttachedTemplate.AutoTextEntries
If optTX.Value = True Then
Set oRng = oBKMs("bmkAltAddress").Range
oRng.Text = oAT("TXAdd")
oBKMs.Add "bmkAltAddress", oRng
End If
Set oRng = oBKMs("bmkTest").Range
Select Case True
Case Me.OB1
oRng.Text = oAT("opt1")
Case Me.OB2
oRng.Text = oAT("opt2")
Case Me.OB3
oRng.Text = oAT("opt3")
End Select
oBKMs.Add "bmkTest", oRng
Me.Hide
Set oRng = Nothing
Set oBKMs = Nothing
Set oAT = Nothing
End Sub
 
C

charlie6067

I've designed a user form that's a mixture of checkboxes and one set
of radio buttons. When the OK button is clicked, each checkbox runs a
macro that inserts a stored autotext entry at a bookmark - that works
great. I want the same action for a group of radio buttons (tbut the
coding method must be different as I'm having problems. Here's the
code for the OK button. Please show me the coding errors. Thanks,
Charlie charlie6067

On of the checkboxes is named optTX.
Autotext entry = TXAdd

Private Sub optTX_Click()
End Sub

Private Sub cmdOK_Click()
' OK Button

If optTX.Value = True Then
' Call TXAdd autotext address for TX

PasswordOff
Application.DisplayAutoCompleteTips = False
With AutoCorrect
.CorrectInitialCaps = True
.CorrectSentenceCaps = True
.CorrectDays = True
.CorrectCapsLock = True
.ReplaceText = True
End With

Selection.GoTo What:=wdGoToBookmark, Name:="bmkALTAddress"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = True
End With

ActiveDocument.AttachedTemplate.AutoTextEntries("TXAdd"). _
Insert Selection.Range, RichText:=True

PasswordOn

End If
End Sub

Thanks for the code Greg. I relied on the macro recorder which
includes a bunch of irrelevant code. Thanks for breaking it down for
me. Anymore, I seldom look in an app's help file because better info
is found in this forum and others.

Have a great weekend!
Charlie
charlie6067
 
C

charlie6067

Charlie,

I don't know about some of your code (seems irrevelent to the issue)
but something like this should do:

I created three option buttons OB1, OB2 and OB3 and three autotext
entries opt1 opt2 and opt3

Private Sub cmdOK_Click()
Dim oRng As Word.Range
Dim oBKMs As Bookmarks
Dim oAT As AutoTextEntries
Set oBKMs = ActiveDocument.Bookmarks
Set oAT = ActiveDocument.AttachedTemplate.AutoTextEntries
If optTX.Value = True Then
Set oRng = oBKMs("bmkAltAddress").Range
oRng.Text = oAT("TXAdd")
oBKMs.Add "bmkAltAddress", oRng
End If
Set oRng = oBKMs("bmkTest").Range
Select Case True
Case Me.OB1
oRng.Text = oAT("opt1")
Case Me.OB2
oRng.Text = oAT("opt2")
Case Me.OB3
oRng.Text = oAT("opt3")
End Select
oBKMs.Add "bmkTest", oRng
Me.Hide
Set oRng = Nothing
Set oBKMs = Nothing
Set oAT = Nothing
End Sub










- Show quoted text -

Thanks for the code Greg. I relied on the macro recorder which
includes a bunch of irrelevant code. Thanks for breaking it down for
me. Anymore, I seldom look in an app's help file because better info
is found in this forum and others.

Have a great weekend!
Charlie
charlie6067
 

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