Make checkbox on user form pass a character to active document?

S

Sandi V

If a checkbox on the user form is selected, then the value "true" is passed
to bookmark the active document. Does anybody know how I can change that and
make a checkmark display instead?

Thanks in advance!
Sandi
 
F

fumei via OfficeKB.com

I do not understand.

If a checkbox on a userform is checked, the checkbox value = True. By itself
this does nothing. The value simply becomes True. Something must pass that
value to something else. What does "passed to bookmark the active document"
mean? The whole document is bookmarked? SOME procedure must do that (if
that is what you mean). If you want to change what that procedure does, then
just change that procedure.

If I make a guess at what you are asking, do you mean how do you make a
procedure check to see what the value of the checkbox is (True or False), and
if True, make a checkmark IN the document, presumably at a bookmark?

Here is an example that puts a box with a "x" in it at a bookmark named
"here"

Private Sub CommandButton1_Click()
If CheckBox1.Value = True Then
ActiveDocument.Bookmarks("here").Range.InsertSymbol _
Font:="Wingdings", CharacterNumber:=-3976, Unicode _
:=True
End If
End Sub
 
S

Sandi V

Thank you -- this is just what I need. Sorry, I neglected to say that I'm
passing values like this:

With ActiveDocument
.Bookmarks("ckPrevClaim").Range.InsertBefore bkPrevClaim
etc.


Your guess was perfect!!
 
G

Gordon Bentley-Mix

Sandi,

If you use CheckBox type formfields you can also do something like this:

Sub SetMyFormFieldCheckboxValue()
With ActiveDocument
If .Bookmarks.Exists("myFormFieldCheckBox") Then
With .FormFields("myFormFieldCheckBox")
If .Type = wdFieldFormCheckBox Then
If myUserFormCheckBox.Value = True Then
.CheckBox.Value = True
Else
.CheckBox.Value = False
End If
End If
End With
End If
End With
End Sub

This assumes you have a CheckBox formfield in your template / document
called "myFormFieldCheckBox" and a related CheckBox control on your UserForm
called "myUserFormCheckBox".

I've just completed a template that has a heap of CheckBox formfields on it
(and, of course, an equal number of CheckBox controls in the UserForm), so I
actually created a procedure that accepts arguments to do this. It looks
something like this:

Sub SetCheckboxValue(BkmkName As String, ByVal myValue As Boolean)
With ActiveDocument
If .Bookmarks.Exists(BkmkName) Then
With .FormFields(BkmkName)
If .Type = wdFieldFormCheckBox Then .CheckBox.Value = myValue
End With
End If
End With
End Sub

I call this procedure thusly:

Private Sub InsertRequiredDocumentsDetails()
SetCheckboxValue "chkELFA", chkELFA.Value
SetCheckboxValue "chkSSA", chkSpecificSecurityAgreement.Value
End Sub

Actually, it's not *exactly* like that because I don't work with the
ActiveDocument object; I instantiate an instance of a Document object and set
it to the ActiveDocument, and then refer to this specific Document object. I
also collect the information from the various UserForm controls and then
unload the UserForm prior to putting content into the document. So in my code
there are no references to 'ActiveDocument' or to any particular UserForm
control. Instead I refer to 'myDoc' (which is the specific Document object
mentioned above) and pass the Boolean variables that are used to collect the
information from the .Value properties of the UserForm CheckBox controls...

But you get the idea. ;-D

Email me if you have questions.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 

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