#1
|
|||
|
|||
Code to reload userform checkbox value after unload
My apologies if I phrase this incorrectly, but I have self-taught myself some VBA based on threads here and on a few other forums.
I have a userbox that has textboxes that links to document variables and a checkbox named ChxMultiDef. When I unload the userform, I need a way to save the value of the checkbox so if I reopen the userform, the value of the checkbox comes back. I have found a way to do this for my textboxes/document variables, but not for the checkbox values. This is what I do for the For the textboxes/document variables, my code in the "OK" button is: With ActiveDocument AND my code in the Userform_initialize is: With ActiveDocumentWhen I do this, when i unload the userform and then reload it, the textbox information is back. I just cannot figure out how to do the same with the checkbox. Also, I cannot use the Me.Hide for a long reason that isn't necessary to explain here. And I don't want to save to the registry. When I have looked on excel forums, they seem to save to a hidden cell, but I don't think that works for Word. Any advice would be greatly appreciated -- I've been pulling my hair out for days on this issue. |
#2
|
|||
|
|||
See Create a Simple Userform by Graham Mayor, MVP. It is a long page. He gives examples on reloading a userform.
|
#3
|
|||
|
|||
Thanks Charles -- I frequently find helpful information in yours and Graham's posts. I have read that post and I can't find info on the checkbox values. Basically, if the checkbox is clicked (or unclicked) when the userform is closed, i want the checkbox to remain clicked (or unclicked) when i reopen the userform again.
|
#4
|
||||
|
||||
Checkboxes don't typically have a name that begins txt. Are you sure it is a checkbox and not a textbox?
The type of the userform textbox and the variable must match with the code you are using. If one is a string and the other is a boolean then you will need to convert it. For example, does ActiveDocument.Variables("plaintiff").Value return "True" or True? These are different - one is a string and one is a boolean. Can document variables hold anything other than strings? Perhaps try to initialize the value with Code:
Me.txtPlaintiff.Value = ActiveDocument.Variables("plaintiff").Value = "True"
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
Sorry, I wasn’t clear—the code I posted was what I am using for my textboxes. I need something for the checkboxes, because I can’t seem to get the textbox code to work for the checkboxes. And the textboxes relate to variables but the checkboxes don’t (they deal with bookmarks). I hope that makes sense. 😞
|
#6
|
||||
|
||||
You need to store the value somewhere, or read it directly from the document e.g.
Code:
Private Sub CommandButton1_Click() ActiveDocument.Variables("varMultiDef").value = ChxMultiDef.value Unload Me End Sub Private Sub UserForm_Initialize() Dim oVar As Variable For Each oVar In ActiveDocument.Variables Select Case oVar.Name Case Is = "varMultiDef" ChxMultiDef.value = oVar.value Case Else End Select Next oVar End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#7
|
|||
|
|||
Solved
Graham, I cannot thank you enough! This worked perfectly! Thank you!
|
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
The Word userform checkbox (checked/unchecked) is not saved on the Application Quit | matapagi2019 | Word VBA | 3 | 03-31-2019 02:29 AM |
Show Userform when Content Control CheckBox ticked | derajlance | Word VBA | 1 | 05-13-2016 01:55 PM |
VBA Code in a UserForm module to delete a Command Button which opens the userform | Simoninparis | Word VBA | 2 | 09-21-2014 03:50 AM |
Checkbox in Userform | lukael | Excel Programming | 5 | 02-18-2014 05:20 AM |
Checkbox on Userform result in Text in Word | Dolfie_twee | Word VBA | 1 | 06-22-2010 07:54 AM |