Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.word.tables
TomorrowsMan
 
Posts: n/a
Default Word Table Calculation VBA

Okay, I think I'm getting there; thanks for all your help out there...

So here's where I stand: I have my rows of check boxes in a table; I
need the user to be able to select only one choice [ed.: can't use
buttons in a userform...don't ask, but it was forbidden) per row, which
will be totalled (then multiplied by 60%) later.

The check box groups successfully limit the user to one per row; and
the total calculates for the first row. BUT, that's where I hit the
wall:

When I check a box in the second row, it changes the total in the first
row. GRR! I know it must have to do with them being in groups [as
required by the first bit of code, but likely interfering with the
second], and I'm not sure how to track down where the flaw is.

Here's what I've got so far; the top half I got from you folks, the
rest I found as noted:


Sub SumTableRowCheckBoxes()

' CheckExclusive Macro

Dim oField As FormField

For Each oField In Selection.Frames(1).Range.FormFields
oField.CheckBox.Value = False
Next oField

' FormField Value Macro
' from http://homepage.swissonline.ch/cindymeister/formfaq.htm

Selection.FormFields(1).CheckBox.Value = True
Dim ffldsChkBoxes As Word.FormFields
Dim frmField As Word.FormField
Dim CheckBoxValue As Integer
Dim RunningCheckBoxSum As Integer
Dim currRow As String
Dim frmTotalName As Variant 'Variant because string not accepted

ScreenUpdating = False
If Selection.Information(wdWithInTable) = True Then
'MsgBox Selection.FormFields(1).Name & vbCr &
Selection.FormFields(1).CheckBox.Value
Set ffldsChkBoxes = Selection.Rows(1).Range.FormFields
RunningCheckBoxSum = 0
For Each frmField In ffldsChkBoxes
If frmField.Type = wdFieldFormCheckBox Then
If frmField.CheckBox.Value = True Then
CheckBoxValue = 0
CheckBoxValue = GetValueFromName(frmField.Name)
RunningCheckBoxSum = RunningCheckBoxSum +
CheckBoxValue
End If
End If
Next
currRow = Trim(Str(Selection.Cells(1).RowIndex))
frmTotalName = "Row" & currRow & "Total"
ActiveDocument.FormFields(frmTotalName).Result =
RunningCheckBoxSum
Else
MsgBox "Any checkbox or formfield running this macro must be in
a table."
End If
End Sub

Function GetValueFromName(FormFieldName As Variant)
Dim ValueStartPos As Integer
Dim FormFieldValue As Integer
If InStr(FormFieldName, "Val") Then
ValueStartPos = InStr(FormFieldName, "Val") + 3
FormFieldValue = Mid(FormFieldName, ValueStartPos)
End If
GetValueFromName = FormFieldValue
End Function


I'm so close to getting this thing wrapped up, which will make me very
happy because I can then go back to my much easier Excel and Acrobat
files...but they insist this one remain in Word.

Cheers,
TMan

 
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
Word 97 in Windows XP to maintain formatting Charlie''s Word VBA questions Microsoft Word Help 22 May 20th 23 08:51 PM
Word should allow to 'divide' page by 3 or 4, not just 2 CandasK Page Layout 2 February 28th 06 10:16 PM
Does Word have a QuickCorrect/Quick Word option like WordPerfect? CW New Users 2 December 20th 05 05:54 PM
In Word, how do I surpress headers and footers on page 2 Bill Microsoft Word Help 1 December 15th 05 06:13 PM
Envelope Address GR New Users 5 April 24th 05 09:48 PM


All times are GMT +1. The time now is 11:44 AM.

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"