Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-03-2014, 07:24 AM
ksigcajun ksigcajun is offline Option Button selected will display text Windows 7 64bit Option Button selected will display text Office 2010 64bit
Advanced Beginner
Option Button selected will display text
 
Join Date: May 2014
Posts: 76
ksigcajun is on a distinguished road
Default Option Button selected will display text

Im working with two option buttons in Word and I want to display specific text below each if that button is chosen. Can a simple macro be written?

Here is what should happen.
If Option Button111 is selected, the following text will be displayed, "User will email form."

If Option Button211 is selected, the following text will be displayed, "User will mail form via FedEx."

This is what I got, so far. Am I on the right track? Should I have two seperate macros or can this be written into one?



Thanks!

Code:
Private Sub OptionButton111_Click()
If Me.OptionButton111.Value = True Then
 
End Sub
 
Private Sub OptionButton211_Click()
If Me.OptionButton211.Value = True Then
 
End Sub
Reply With Quote
  #2  
Old 07-03-2014, 10:33 AM
gmaxey gmaxey is offline Option Button selected will display text Windows 7 32bit Option Button selected will display text Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Yes you are on the right track, but ActiveX controls are not ideal for use in Word documents.

You need a range target for the text. It could be a table cell, a paragraph, a bookmark, a content control, a variables (and use a DocVariable field), etc.

Here I have created a bookmark "bmText" to serve as the target range.

Code:
Option Explicit
Dim oBM As Bookmark
Dim oRng As Range
Private Sub OptionButton111_Click()
If Me.OptionButton111.Value = True Then
   Set oRng = ActiveDocument.Bookmarks("bmText").Range
   oRng.Text = "User will email form"
   ActiveDocument.Bookmarks.Add "bmText", oRng
End If
End Sub
 
Private Sub OptionButton211_Click()
If Me.OptionButton211.Value = True Then
  Set oRng = ActiveDocument.Bookmarks("bmText").Range
   oRng.Text = "User will mail form via FedEx"
   ActiveDocument.Bookmarks.Add "bmText", oRng
End If
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 07-03-2014, 10:42 AM
ksigcajun ksigcajun is offline Option Button selected will display text Windows 7 64bit Option Button selected will display text Office 2010 64bit
Advanced Beginner
Option Button selected will display text
 
Join Date: May 2014
Posts: 76
ksigcajun is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
Yes you are on the right track, but ActiveX controls are not ideal for use in Word documents.

You need a range target for the text. It could be a table cell, a paragraph, a bookmark, a content control, a variables (and use a DocVariable field), etc.

Here I have created a bookmark "bmText" to serve as the target range.

Code:
Option Explicit
Dim oBM As Bookmark
Dim oRng As Range
Private Sub OptionButton111_Click()
If Me.OptionButton111.Value = True Then
   Set oRng = ActiveDocument.Bookmarks("bmText").Range
   oRng.Text = "User will email form"
   ActiveDocument.Bookmarks.Add "bmText", oRng
End If
End Sub
 
Private Sub OptionButton211_Click()
If Me.OptionButton211.Value = True Then
  Set oRng = ActiveDocument.Bookmarks("bmText").Range
   oRng.Text = "User will mail form via FedEx"
   ActiveDocument.Bookmarks.Add "bmText", oRng
End If
End Sub
This works great Greg! Thank you so much. Very helpful.

Quick question, is there a way to remove the text if someone changes their mind and wants to chose the other option button? I noticed when I do that now, it leaves the text.

Thanks!
Reply With Quote
  #4  
Old 07-03-2014, 10:54 AM
gmaxey gmaxey is offline Option Button selected will display text Windows 7 32bit Option Button selected will display text Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Here if I choose OptionButton111 the bookmark text is "User will email form." If I change my mind and choose OptionButton211 the bookmark text changes to "User will mail form via FedEx"

I don't know why it wouldn't be working the same for you.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 07-03-2014, 12:15 PM
ksigcajun ksigcajun is offline Option Button selected will display text Windows 7 64bit Option Button selected will display text Office 2010 64bit
Advanced Beginner
Option Button selected will display text
 
Join Date: May 2014
Posts: 76
ksigcajun is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
Here if I choose OptionButton111 the bookmark text is "User will email form." If I change my mind and choose OptionButton211 the bookmark text changes to "User will mail form via FedEx"

I don't know why it wouldn't be working the same for you.
When I do change my mind, the text stays and doesnt go away. I was hoping to choose one and have it display, if I change my mind, it would go away and the new option would display once I select the option button.

Does it currently do that for you?
Reply With Quote
  #6  
Old 07-03-2014, 02:12 PM
gmaxey gmaxey is offline Option Button selected will display text Windows 7 32bit Option Button selected will display text Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Yes, the text displayed here is the text associated with the option button selected.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 07-10-2014, 06:58 AM
ksigcajun ksigcajun is offline Option Button selected will display text Windows 7 64bit Option Button selected will display text Office 2010 64bit
Advanced Beginner
Option Button selected will display text
 
Join Date: May 2014
Posts: 76
ksigcajun is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
Yes, the text displayed here is the text associated with the option button selected.
I've tried for a week and still cant get the text to clear if a user decides to click the other option button.

I'm trying to come up with Plan B. Can I clear the text in the bookmark?

Here is where Im at.

Code:
Option Explicit
Dim oBM As Bookmark
Dim oRng As Range
Private Sub OptionButton111_Click()
ActiveDocument.Undo
If Me.OptionButton111.Value = True Then
   Set oRng = ActiveDocument.Bookmarks("BM2").Range
   oRng.Text = "Bids should be sent via email to the email addresses listed above. In the alternative, if Bidder does not intend to bid on this Project, please submit your confirmation of NO BID via email to the email address listed above."
   ActiveDocument.Bookmarks.Add "BM2", oRng
   If Me.OptionButton211.Value = False Then
   **Not sure what I can add here to clear the text**   
End If
End If
End Sub
 
Private Sub OptionButton211_Click()
ActiveDocument.Undo
ActiveDocument.Undo
If Me.OptionButton211.Value = True Then
  Set oRng = ActiveDocument.Bookmarks("BM3").Range
   oRng.Text = "All bids must be sealed and received at the address listed above. Any bid received after that time may, at COMPANY'S sole discretion, be returned unopened.  The bid opening will be private. In the alternative, if Bidder does not intend to bid on this Project, please submit your confirmation of NO BID via email to the email addresses listed above."
   ActiveDocument.Bookmarks.Add "BM3", oRng
   If Me.OptionButton211.Value = False Then
**Not sure what I can add here to clear the text**
   End If
    End If
End Sub
Reply With Quote
  #8  
Old 07-14-2014, 09:31 AM
ksigcajun ksigcajun is offline Option Button selected will display text Windows 7 64bit Option Button selected will display text Office 2010 64bit
Advanced Beginner
Option Button selected will display text
 
Join Date: May 2014
Posts: 76
ksigcajun is on a distinguished road
Default

Nevermind, Greg.

I was able to correct the issue. Thanks again for the help!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Display paragraph of text based on value selected in combo WordWaza Word 0 08-09-2013 06:30 AM
Option Button selected will display text Can you create a button that indicates the status of markup display? New Daddy Word 1 01-25-2013 12:35 AM
Recent file display option at MS word Patrick Lau Word 0 08-16-2010 11:22 PM
Help on option button active X aligahk06 Excel 0 11-03-2009 11:39 PM
Option Button ( ACtive X Control ) aligahk06 Excel 0 11-03-2009 06:36 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:34 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft