Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2006

Tip: Looking for answers? Try searching our database.

Word 2003

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bobbyb0y@hotmail.com - 28 Dec 2006 16:53 GMT
I'm working on a Word  form to capture ratings for a set of categories.
Each of these categories have radios buttons that correspond to numeric
values 1 through 5. I was able to create a individual groups that
correspond to each of my categories. I also have 5 text form fields,
labeled "ones", "twos", "threes", "fours" and "fives",  that need need
to display in how many ever 1's or 2's, etc. are chosen cumulatively.
Example, if  I have three selected radio buttons that correspond to
score 5, then the "fives" text form field must display 3. How can I
create a script or macro that updates the text form field values
corresponding to the related radio button clicks? Is there some script
that someone can share. This must be really simple, I'm a programmer
myself. But I'm completely new to the VBscipt and do not know where to
start.

TIA.
Doug Robbins - Word MVP - 28 Dec 2006 18:43 GMT
Exactly what type of form is this?  Does it use formfields that require the
document to be Protected for Forms to operate? or is it a UserForm?  or have
you inserted the visual basic controls directly in the document?

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> I'm working on a Word  form to capture ratings for a set of categories.
> Each of these categories have radios buttons that correspond to numeric
[quoted text clipped - 11 lines]
>
> TIA.
bobbyb0y@hotmail.com - 28 Dec 2006 19:31 GMT
Yes it does use formfields and I protect the form. I'm creating a .dot
template document (pardon my jargon here).  I'm currently
unlocking/unprotecting the form and then clicking on the "Design Mode"
icon to drag the "option button" onto the form.This option button is
what I meant by the radio button in my previous post.
Doug Robbins - Word MVP - 29 Dec 2006 09:04 GMT
With three sets of five option buttons named:

Option 11, Option 21, Option 31, Option 41, Option 51
Option 12, Option 22, Option 32, Option 42, Option 52
Option 13, Option 23, Option 33, Option 43, Option 53

and the formfields named as you have them, this is the code that you would
need:

Public o11 As Long, o12 As Long, o13 As Long, one As Long
Public o21 As Long, o22 As Long, o23 As Long, two As Long
Public o31 As Long, o32 As Long, o33 As Long, three As Long
Public o41 As Long, o42 As Long, o43 As Long, four As Long
Public o51 As Long, o52 As Long, o53 As Long, five As Long

Private Sub Option11_Click()
If Option11.Value = True Then
   o11 = 1
   o21 = 0
   o31 = 0
   o41 = 0
   o51 = 0
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub
Private Sub Option21_Click()
If Option21.Value = True Then
   o11 = 0
   o21 = 1
   o31 = 0
   o41 = 0
   o51 = 0
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub
Private Sub Option31_Click()
If Option31.Value = True Then
   o11 = 0
   o21 = 0
   o31 = 1
   o41 = 0
   o51 = 0
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub
Private Sub Option41_Click()
If Option41.Value = True Then
   o11 = 0
   o21 = 0
   o31 = 0
   o41 = 1
   o51 = 0
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub
Private Sub Option51_Click()
If Option51.Value = True Then
   o11 = 0
   o21 = 0
   o31 = 0
   o41 = 0
   o51 = 1
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub

Private Sub Option12_Click()
If Option12.Value = True Then
   o12 = 1
   o22 = 0
   o32 = 0
   o42 = 0
   o52 = 0
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub
Private Sub Option22_Click()
If Option22.Value = True Then
   o12 = 0
   o22 = 1
   o32 = 0
   o42 = 0
   o52 = 0
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub
Private Sub Option32_Click()
If Option32.Value = True Then
   o12 = 0
   o22 = 0
   o32 = 1
   o42 = 0
   o52 = 0
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub
Private Sub Option42_Click()
If Option42.Value = True Then
   o12 = 0
   o22 = 0
   o32 = 0
   o42 = 1
   o52 = 0
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub
Private Sub Option52_Click()
If Option52.Value = True Then
   o12 = 0
   o22 = 0
   o32 = 0
   o42 = 0
   o52 = 1
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub

Private Sub Option13_Click()
If Option13.Value = True Then
   o13 = 1
   o23 = 0
   o33 = 0
   o43 = 0
   o53 = 0
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub
Private Sub Option23_Click()
If Option23.Value = True Then
   o13 = 0
   o23 = 1
   o33 = 0
   o43 = 0
   o53 = 0
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub
Private Sub Option33_Click()
If Option33.Value = True Then
   o13 = 0
   o23 = 0
   o33 = 1
   o43 = 0
   o53 = 0
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub
Private Sub Option43_Click()
If Option43.Value = True Then
   o13 = 0
   o23 = 0
   o33 = 0
   o43 = 1
   o53 = 0
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub
Private Sub Option53_Click()
If Option53.Value = True Then
   o13 = 0
   o23 = 0
   o33 = 0
   o43 = 0
   o53 = 1
End If
one = o11 + o12 + o13
two = o21 + o22 + o23
three = o31 + o32 + o33
four = o41 + o42 + o43
five = o51 + o52 + o53
With ActiveDocument
   .FormFields("Ones").Result = one
   .FormFields("Twos").Result = two
   .FormFields("Threes").Result = three
   .FormFields("Fours").Result = four
   .FormFields("Fives").Result = five
End With
End Sub

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Yes it does use formfields and I protect the form. I'm creating a .dot
> template document (pardon my jargon here).  I'm currently
> unlocking/unprotecting the form and then clicking on the "Design Mode"
> icon to drag the "option button" onto the form.This option button is
> what I meant by the radio button in my previous post.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.