Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
bizhub bizhub is offline
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Cindy M. Cindy M. is offline
external usenet poster
 
Posts: 2,416
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Repeating Text (Client Name) Through Document CBevers Microsoft Word Help 2 December 19th 06 03:54 PM
How do I lock portion of the document? Sesame Microsoft Word Help 6 October 25th 06 04:35 PM
Need to Create a Client Directory Mail Merge Document zachmattsmom Mailmerge 1 October 13th 05 09:02 PM
Templates chnaging client codes bec Microsoft Word Help 0 September 23rd 05 07:01 AM
Selecting email client to use with email merge sjmilldr Mailmerge 0 December 17th 04 04:41 PM


All times are GMT +1. The time now is 08:50 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"