Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-27-2018, 01:09 AM
Fissure Fissure is offline Need help with userform and radio buttons Windows 10 Need help with userform and radio buttons Office 2013
Novice
Need help with userform and radio buttons
 
Join Date: Apr 2018
Posts: 2
Fissure is on a distinguished road
Default Need help with userform and radio buttons

Hi there working on a word document and having some issues with some quality of life functions.

The document uses a userform where the user inputs some base data and then the userform fills it into the right areas in the document. There is also some different choices available for the user to check using radio buttons. They each hide certain text depending on the radio button chosen. So far it all works as expected but I am having issues when users reopen the document after saving. The radio buttons are blank and have to be pressed again. This requires the user recheck them again and increases the risk of chosing the wrong stuff or forgetting pressing them.
Now I know this is the way radio buttons work but I am wondering if there is a way to make them be pre selected depending on what text within a certain bookmark is hidden or not in the document.

tried the follwing within userform_Activate ()
With ActiveDocument
If ActiveDocument.Bookmarks("LJSidor1").Range.Font.Hi dden = True Then
Me.LJNejKnapp = True
Else
Me.LJJaKnapp = True
End If
End With

Where "LJSidor1" is one of the bookmarks that hides a certain part of the document depending on the choice of the "LJNejKnapp" button or "LJJaKnapp" button.

Is it possible to do something like this or am I wasting my time, is there any other way to accomplish the same thing?


Any help would be appriciated !



//john
Reply With Quote
  #2  
Old 04-27-2018, 03:02 AM
eduzs eduzs is offline Need help with userform and radio buttons Windows 10 Need help with userform and radio buttons Office 2010 32bit
Expert
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default

One way I use to save the state of controls on the user form is to save them as document variable whenever the user form is hidden or unloaded. Is there another way to save, then to the Windows registry, but I'd rather save inside the document only.
The code is not working? Is there a error message?:
__________________
Backup your original file before doing any modification.
Reply With Quote
  #3  
Old 04-27-2018, 03:44 AM
Fissure Fissure is offline Need help with userform and radio buttons Windows 10 Need help with userform and radio buttons Office 2013
Novice
Need help with userform and radio buttons
 
Join Date: Apr 2018
Posts: 2
Fissure is on a distinguished road
Default

There is no error message from the code above but it always defaults to Me.LJJaKnapp = True now. So the first if part seems to not be correct / do anything.

Guess I will have to look up your tip there since I have no idea what that is or how to do it!
Reply With Quote
  #4  
Old 04-27-2018, 04:07 AM
slaycock slaycock is offline Need help with userform and radio buttons Windows 7 64bit Need help with userform and radio buttons Office 2016
Expert
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

Quote:
Is it possible to do something like this
Yes it is very possible to do this and your sample code shows you are thinking along the right lines. The reason you can use this approach is that the 'metadata' you will use to set the status of the radiobuttons is captured in the hidden property of text in the bookmark range.

I would suggest that the user form initialisation event is the best place for your code.

Code:
Private Sub UserForm_Initialize()

    ' for each bookmark you need a line of code similar to

    Me.LJNejKnapp = ActiveDocument.Bookmarks("LJSidor1").Range.Font.Hidden

    ' which assumes that if hidden = true then you want Me.LJNejKnapp also to be true
    ' if you want the opposite then put a 'Not' before Active document

    ' e.g. Me.LJNejKnapp = Not ActiveDocument.Bookmarks("LJSidor1").Range.Font.Hidden

    ' If your radio buttons are grouped, so that selecting one automatically switches the others in the groups to off
    ' you only need one of the lines above per group.


End Sub
Let us know if this remommendation meets your needs.
Reply With Quote
  #5  
Old 04-27-2018, 04:10 AM
gmayor's Avatar
gmayor gmayor is offline Need help with userform and radio buttons Windows 10 Need help with userform and radio buttons Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Try the following

Code:
Private Sub UserForm_Activate()
Dim oBM As Bookmark
    With ActiveDocument
        If .Bookmarks.Exists("LJSidor1") = True Then
            Set oBM = .Bookmarks("LJSidor1")
            If oBM.Range.Font.Hidden = True Then
                MsgBox "hidden"
                LJNejKnapp.value = True
            Else
                MsgBox "not hidden"
                LJJaKnapp.value = True
            End If
        Else
            MsgBox "missing"
            LJNejKnapp.value = False
            LJJaKnapp.value = False
        End If
    End With
End Sub
I have put in some message boxes so you can see what is reported.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Tags
radio button, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Radio Buttons in Word Document in MAC Office 2016 kim88 Word 3 12-19-2016 03:36 PM
Radio buttons in a particular page gets disabled when i scroll down and return back to that page. arnprd Word 0 06-18-2015 10:54 AM
check box issue (problem with radio buttons from web page) Word 2013 cQQlgirl Word 6 03-19-2015 07:23 PM
Need help with userform and radio buttons Performance problem ActiveX radio buttons NobodysPerfect Word VBA 8 05-31-2014 03:51 AM
example of radio buttons in for data entry? derohanes Excel 1 03-05-2011 09:37 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:22 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