Code for Checkboxes

G

Gordon Bentley-Mix

I'm sure this has been asked and answer previously, but I can't seem to find
the relevant post.

I'm trying to mimic the look of a Word form but without the form controls -
no formfields, no option buttons and, most importantly, no checkboxes.
However, I still want it to look like it's a form as much as possible -
_especially_ the checkboxes. Consequently, I want to insert something that
looks like a checkbox - either selected or deselected as appropriate - into
the correct location in the document. I've got most of it sussed, but I just
can't remember the code for selected and unselected checkboxes.

Direction that proves helpful will be rewarded with a beverage of your
choice at the Botany Downs "Cock 'n Bull". (Transport to said location will
be the winner's responsibility. <g>)
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 
G

Gordon Bentley-Mix

Let me rephrase: I'm looking for the Char codes for a checked and unchecked
checkbox.
 
M

macropod

Hi Gordon,

The macro recorder is your friend!

Sub DoCheckBoxes()
' Checked checkbox
Selection.InsertSymbol Font:="Wingdings", CharacterNumber:=-3976, Unicode:=True
' Unhecked checkbox
Selection.InsertSymbol Font:="Wingdings", CharacterNumber:=-3928, Unicode:=True
End Sub
 
G

Gordon Bentley-Mix

~sigh~

I don't know where all this BS about macrobuttons and such came from. All I
want is the character codes for checked and unchecked checkboxes - assuming
that there are ones. I *thought* I was being clear but obviously not.

Never mind. I'll work it out myself. Guess that's what I get for being lazy.
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 
M

Morse Coder

Gordon, how did you fake out buttons and input fields? And the form-window
itself?
 
G

Gordon Bentley-Mix on news.microsoft.com

OK, a bit of background:

This template (and several other similar templates) started life as a
standard Word XP form - updated to Word 2003 - with text formfields,
dropdowns and checkboxes. However, because of limitations with a form, I
decided to convert it into a "real" template with VBA automation for
collecting the data. This allowed me to overcome some of the form-related
limitations; e.g. collecting multiple "sets" of related information (details
about the parties to a contract, details of multiple disbursements of funds,
etc.); more than 25 items in a dropdown list; inclusion/exclusion of large
blocks of text in accordance with business rules driven by the data; etc.
This also allows easier data validation and formatting, and the codification
of business rules to drive the creation of the document

Now the document is built primarily by inserting the information into
bookmarks - either as AutoText entries (for the large blocks of variable
text) or by building strings using a combination of data from the UserForm
and boilerplate text. I can do all of this quite easily with one exception: I
cannot find a way to replace the CheckBox type formfields with text that
looks like a checked or unchecked checkbox.

Currently, I'm continuing to use CheckBox formfields and set the "state" of
the checkbox based on the data from the UserForm. However, this means that
the users can change the state of any particular checkbox in the final
document. Normally, this would not be much of a concern, but I have designed
the template to allow the user to rerun the template by storing the data from
the UserForm in document variables and using this information to "initialise"
the UserForm on rerun. However, if the user manually changes the state of a
checkbox, this change is not replicated back to the UserForm. And then when
the document is recreated, the checkbox gets reset to whatever the value is
in the UserForm.

I suppose I could always "read" the state of the checkboxes in the document
and use _this_ information to initialise the UserForm on rerun, but this is
probably more work than it's worth. What I would prefer to do is replace the
CheckBox formfields with something that _looks_ like a checkbox - a symbol or
some such - and I was hoping that I could use the Chr function to do this
since it really needs to be part of the string that I insert into a bookmark.
However, it appears that this isn't possible as there are no characters
available to the Chr function for checked and unchecked checkboxes. The
closest appears to be some process that uses the InsertSymbol method that
Paul has suggested. However, I'm not sure that this will work with a Range
object, since I try to avoid changing the selection and using the Selection
object; all of my code works with the .Range of the specified Bookmark.

I could also make the final document Read-Only rather than Forms Protected,
but I need an editable section to allow the input of freeform text
post-document creation; Read-Only doesn't support this.

No matter. I'll just stick with the CheckBox formfields for the time being,
and if the user manually changes one and then reruns the template... well...
~shrug~
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 
J

Jay Freedman

Hi Gordon,

Sorry I didn't look at this thread earlier, because I could have saved you some
time.

The checked and unchecked box characters are in the Wingdings font at decimal
254 and 168, respectively. Our colleague Greg Maxey uses them in his MacroButton
fields in http://gregmaxey.mvps.org/Add_Toggle_Objects.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
G

Gordon Bentley-Mix

Cheers Jay! You're a legend! Have you reconsidered sharing a room at the
next Summit? No more code-driven flying bed dreams, I promise... <g>
 
J

Jay Freedman

Warning: I snore. The poor bloke who drew the short straw at the last Summit
wasn't happy.
 

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