A Microsoft Word forum. Microsoft Office Word Forum - WordBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Microsoft Office Word Forum - WordBanter forum » Microsoft Word Newsgroups » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

How to average values from 6 different drop downs in a separate text box?



 
 
Thread Tools Display Modes
  #1  
Old October 8th 12, 08:09 PM
jscranton jscranton is offline
Junior Member
 
First recorded activity by WordBanter: Oct 2012
Posts: 1
Default How to average values from 6 different drop downs in a separate text box?

I have a form with six different content control fields (all drop downs) that allow a user to rate an employee from 1 to 5. Each has a unique name.

What I would like to do is average all six values and put the result in a text box elsewhere on the form. Ideally, this would update dynamically.

I tried initially to accomplish this with the code below. This almost works. This creates a array for each of the six values [I have only pasted one below] and then populates the value with 1 to 5 depending on the user's selection.

The problem is that the sub resets after each event (On Exit) so the array only contains the most recently selected value.

Is there a fix to this or another way entirely to accomplish this task?

Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)


Dim averageValues(0 To 5) As Integer
Dim i As Integer
Dim totalFields As Integer
Dim totalValue As Long



Select Case ContentControl.Title

'this is the first of six drop downs

Case "Project Knowledge"

        If ContentControl.Range.Text = "Poor" Then
            
                averageValues(0) = 1
                
            ElseIf ContentControl.Range.Text = "Needs Improvement" Then
                
                averageValues(0) = 2
            
            ElseIf ContentControl.Range.Text = "Satisfactory" Then
            
                averageValues(0) = 3
            
            ElseIf ContentControl.Range.Text = "Good" Then
            
                averageValues(0) = 4
            
            ElseIf ContentControl.Range.Text = "Excellent" Then
            
                averageValues(0) = 5
            
        End If

'loop through the array and find all populated values
For i = 0 To 5

    If averageValues(i)  0 Then
    
        totalFields = totalFields + 1
        totalValue = totalValue + averageValues(i)
        
    End If
Next i


    If totalFields   0 Then
    
        MsgBox totalValue / totalFields
    Else
        Exit Sub
    End If
    

End Sub
Ads
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Track changes in a form made to text boxes, drop downs selected, [email protected] Microsoft Word Help 1 April 17th 09 07:22 AM
How do I modify the values in the text or frame box? Bobbie Microsoft Word Help 1 June 22nd 06 05:34 PM
Drop downs and Free text Darius Microsoft Word Help 2 February 17th 06 03:44 PM
The drop down form field is not showing drop downs. Why? mindysue Microsoft Word Help 1 May 26th 05 09:43 PM
drop down box values from excel list sallu Microsoft Word Help 1 May 18th 05 02:17 PM


All times are GMT +1. The time now is 06:13 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright 2004-2021 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.