Help Making a Form Field an Output Box....

C

cwangosu

This is tied in with my previous message, but I thought I'd try to
explain my situation better.

I have a variety of form fields where a user inputs text or selects a
dropdown and receives points based on this. I have used a variety
of "Cases" to accomplish this. Right now, I have a counter which is
displayed after the last form field is filled in and displays this
total point value as a message box.

Instead what I'd like is for a form field named "Text1" to display
this total point value. Unfortunately, it's not working, because the
form is protected and it gives an error. Any help would be
appreciated...

Here's part of my code...

'=========================================================
Function TotalCount() As Boolean
Dim TotalInteger As Integer
Dim objField As FormField
Dim strFieldName As String
Dim strResult As String
Dim num As Integer
Dim chk As Boolean



For Each objField In ActiveDocument.FormFields
strFieldName = objField.Name
Select Case strFieldName

'txtFirstName, txtLastName, txtPSNum
'Award one point for completion
Case "txtFirstName", "txtLastName", "txtPSNum"
strResult = objField.Result
If strResult <> "" Then
TotalInteger = TotalInteger + 1
'Point Given For Completion
TotalCount = True
End If

'drpChampApprove
'Award three points for champion approval
Case "drpChampApprove"
num = objField.DropDown.Value
If num = 1 Then
'(Select One)
TotalInteger = TotalInteger + 0
MsgBox "You have earned " & TotalInteger & " points for completing
this form "
ElseIf num = 2 Then
'Yes
TotalInteger = TotalInteger + 3
MsgBox "You have earned " & TotalInteger & " points for completing
this form "
Else
'No
TotalInteger = TotalInteger + 0
MsgBox "You have earned " & TotalInteger & " points for completing
this form "
TotalCount = True
End If

Case Else
TotalCount = False
End Select
Next objField
End Function
 
G

Greg

Adding the following line above your three message boxes
works for me:

ActiveDocument.FormFields("Text1").Result = TotalInteger

If I may ask, why are you using a Function? I changed
this to a Sub and set it to run on exit from the dropdown
field. Here is a modified version:

Option Explicit
Sub Score()
Dim Score As Long
Dim objField As FormField
Dim strFieldName As String
Dim strResult As String
Dim num As Integer
Dim chk As Boolean
Dim Text1 As FormField

For Each objField In ActiveDocument.FormFields
strFieldName = objField.Name
Select Case strFieldName
Case "txtFirstName", "txtLastName", "txtPSNum"
strResult = objField.Result
If strResult <> "" Then
Score = Score + 1
End If

Case "drpChampApprove"
num = objField.DropDown.Value
If num = 2 Then
Score = Score + 3
ActiveDocument.FormFields("Text1").Result = Score
MsgBox "You have earned " & Score & " points for
completing this form "
Else
Score = Score + 0
ActiveDocument.FormFields("Text1").Result = Score
MsgBox "You have earned " & Score & " points for
completing this form "
End If
Case Else
Exit For
End Select
Next objField
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top