PDA

View Full Version : Solved: how to toggle a checkbox?



Bob Workman
06-09-2005, 01:14 PM
Advice for newbie, please: how I can make this checkbox 'toggle-able' in a Word doc?
My 2-line subroutine lets the user double click a macrobutton to change an empty check box to a checked box, but the user can't toggle back to an empty box if they make a mistake. It needs to allow the user to toggle between an empty box (Wingdings unicode 61608) and a checked box (Wingdings unicode 61694) until satisfied. (It also perhaps rashly assumes it's safe to expect the user has the Wingdings font...dare I do that? If not, ...what?) Thank you,

Sub togglecheckbox()
'
' This togglecheckbox Macro works with the following macrobutton:
' macrobutton togglecheckbox (wingdings unicode char 61608)
'
Selection.Font.Name = "Wingdings"
Selection.TypeText Text:=ChrW(61694)
End Sub

Jacob Hilderbrand
06-09-2005, 01:22 PM
Just use a Check Box Form Field.

Bring up the Forms toolbar, then add a Check Box. Click the Protect Form button on the Forms toolbar are you can change the Check Boc by clicking it.

Bob Workman
06-09-2005, 01:44 PM
Outa sight! Thanks, Jake!

Bob Workman
06-09-2005, 04:25 PM
Oops, there's one problem with that approach: I need the checkboxes to display right in with the Word document's text, not within a forms window.....

Jacob Hilderbrand
06-09-2005, 05:28 PM
Like this?

Bob Workman
06-10-2005, 05:47 AM
Exactly! Nice demo, but how to do it with a macro is the real question! Seems to me it may require a macro that invokes a macrobutton that re-creates itself with different parameters depending on its previous iteration. Now that would be a trick! However, being famous for inventing overcomplicated Rube Goldberg solutions to simple problems, I hesitate to proceed without an expert's concurrence that I'm moving in the right direction.

MOS MASTER
06-10-2005, 02:34 PM
Exactly! Nice demo, but how to do it with a macro is the real question! Seems to me it may require a macro that invokes a macrobutton that re-creates itself with different parameters depending on its previous iteration. Now that would be a trick! However, being famous for inventing overcomplicated Rube Goldberg solutions to simple problems, I hesitate to proceed without an expert's concurrence that I'm moving in the right direction.
Hi, :yes

Yes this can be done without using Formfield checkboxes and without protecting the document.

If working in a protected document Jakes option is the easiest but there are others. (Does involve code)

If you're still looking for such a sollution I'll post it tomorrow..Have little time now...:whistle:

Bob Workman
06-10-2005, 03:31 PM
Thanks, Joost, yes, for the intended purpose of the document, it would not be feasible to protect the document - so clues on how to proceed with code will be most welcome.

MOS MASTER
06-11-2005, 11:25 AM
Hi Bob, :yes

Ok You'll need two Autotextentries Like:

{ MACROBUTTON UNCHECKIT (Symbol representing checked box)} (Autotext name: Unchecked Box)
{ MACROBUTTON CHECKIT (Symbo representing unchecked box) } (Autotext name: Checked Box)
They will fire these 2 macro's:
Option Explicit
Public lFieldClicks As Long
Sub CheckIt()
ActiveDocument.AttachedTemplate.AutoTextEntries _
("Checked Box").Insert Where:=Selection.Range
End Sub
Sub UncheckIt()
ActiveDocument.AttachedTemplate.AutoTextEntries _
("Unchecked Box").Insert Where:=Selection.Range
End Sub


Further more macrobutton will normaly work after double-clicking but you can change that with code to one click to have it work with only one click. In the codepane of ThisDocument:
Option Explicit
Private Sub Document_Close()
Options.ButtonFieldClicks = lFieldClicks
End Sub
Private Sub Document_New()
lFieldClicks = Options.ButtonFieldClicks
Options.ButtonFieldClicks = 1
End Sub
Private Sub Document_Open()
lFieldClicks = Options.ButtonFieldClicks
Options.ButtonFieldClicks = 1
End Sub

The Public variable lFieldClicks will hold the value as it was when you opened the document and set it back on closure so the environment will stay the same.

This is a bith much so I've added a attachment so you can see how it works.

Enjoy! :whistle:

fumei
06-13-2005, 08:32 AM
I am not understanding the proble,.

You can use either a formfield checkbox (in a protected section), or a ActiveX checkbox control.

Either one allows the user to toggle the checkbox as checked, or unchecked, as much as they like.

Could you restate the issue?

MOS MASTER
06-13-2005, 09:53 AM
I am not understanding the proble,.

Hi Gerry,

True and True! :yes

My excuse for making this was because a client wanted a custom checkbox that looked more elegant then the builtin stuff (ActiveX or Formfield) And this seams to be a elegant sollution indeed.

So I had it lying arround and I thought that Bob was looking for a simular deal.

Well Bob...have you found yet what you're looking for? :whistle:

Bob Workman
06-13-2005, 02:27 PM
Hi Gerry,

True and True! :yes

My excuse for making this was because a client wanted a custom checkbox that looked more elegant then the builtin stuff (ActiveX or Formfield) And this seams to be a elegant sollution indeed.

So I had it lying arround and I thought that Bob was looking for a simular deal.

Well Bob...have you found yet what you're looking for? :whistle:
The solution is perfect - would have gotten back sooner except have been sidetracked with some pesky computer network problems. Thank you for sharing this code - it is very helpful!

MOS MASTER
06-14-2005, 09:46 AM
The solution is perfect - would have gotten back sooner except have been sidetracked with some pesky computer network problems. Thank you for sharing this code - it is very helpful!
Hi Bob, :yes
You're Welcome! :beerchug: