Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Limit # of checkboxs a client can use
I have a form that contains several checkboxes and I want to limit the number
that a client can choose to only 2 and if they try to choose 3 have a message pop up that they are only allowed 2 choices. How can I accomplish this. Thanks in advance for any help. |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Limit # of checkboxs a client can use
Hi ?B?Yml6aHVi?=,
I have a form that contains several checkboxes and I want to limit the number that a client can choose to only 2 and if they try to choose 3 have a message pop up that they are only allowed 2 choices. This would require a macro. If we're talking about form field checkboxes, then the macro can only fire when the user enters or exits a checkbox (not "on click"). Here's a pair of macros to show how it can be done. Assign CheckNumberOfCheckedBoxes to the EXIT property all the checkboxes you want to include in the test (in the form field Options dialog box). Assign ReturnToField to the ENTER property of the same checkboxes. The first loops through all the formfields in the document, tests whether they're checkboxes and activated. A counter is updated if they are, then compared against the total number of allowed checkboxes. If this number is exceeded, the message is displayed and a variable set to indictate control needs to stay in the field where the message was triggered. As focus moves into the next field, this value is checked and focus returned to the checkbox that triggered the message (you can leave this part out, if you wish). Private ffldCurrent As Word.FormField Private boolReturn Sub CheckNumberOfCheckedBoxes() Dim doc As Word.Document Dim ffld As Word.FormField Dim checkCounter As Long Dim checkAllowedTotal As Long checkAllowedTotal = 2 checkCounter = 0 Set doc = ActiveDocument Set ffldCurrent = Selection.FormFields(1) For Each ffld In doc.FormFields If ffld.Type = wdFieldFormCheckBox Then If ffld.CheckBox.Value = True Then checkCounter = checkCounter + 1 If checkCounter checkAllowedTotal Then MsgBox "You are allowed to check only two options." boolReturn = True Exit For End If End If End If Next End Sub Sub ReturnToField() If boolReturn Then boolReturn = False ffldCurrent.Select End If End Sub Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005) http://www.word.mvps.org This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-) |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Repeating Text (Client Name) Through Document | Microsoft Word Help | |||
How do I lock portion of the document? | Microsoft Word Help | |||
Need to Create a Client Directory Mail Merge Document | Mailmerge | |||
Templates chnaging client codes | Microsoft Word Help | |||
Selecting email client to use with email merge | Mailmerge |