Hiya - first post alert!

I'm try to get word to form a sentence from user selected checkboxes,
for example a user selects the items that they want and then word
forms a sentence such as "i want X, Y and Z" So that it inserts commas
and the word "and" in the correct place.

i tried having a count, for the items and then when the count is > 1
getting word to type ", " but this code never called.

any help please?

Re: Forming a sentence from a checkbox list by Doug

Doug
Fri Jul 11 01:41:09 PDT 2008

What type of form/checkboxes?

--
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

<trance4mason@gmail.com> wrote in message
news:aee3204c-291b-40af-9a16-b155cd6ce52b@34g2000hsf.googlegroups.com...
> Hiya - first post alert!
>
> I'm try to get word to form a sentence from user selected checkboxes,
> for example a user selects the items that they want and then word
> forms a sentence such as "i want X, Y and Z" So that it inserts commas
> and the word "and" in the correct place.
>
> i tried having a count, for the items and then when the count is > 1
> getting word to type ", " but this code never called.
>
> any help please?



Re: Forming a sentence from a checkbox list by fumei

fumei
Fri Jul 11 10:25:16 PDT 2008

And it may help if you posted some actual code.

trance4mason@gmail.com wrote:
>Hiya - first post alert!
>
>I'm try to get word to form a sentence from user selected checkboxes,
>for example a user selects the items that they want and then word
>forms a sentence such as "i want X, Y and Z" So that it inserts commas
>and the word "and" in the correct place.
>
>i tried having a count, for the items and then when the count is > 1
>getting word to type ", " but this code never called.
>
>any help please?

--
Message posted via http://www.officekb.com


Re: Forming a sentence from a checkbox list by Gregory

Gregory
Fri Jul 11 18:34:56 PDT 2008

Lets assume that you are talking about formfield checkboxes in a protected
document.

I created 8 checkboxes bookmarked "Check1" through "Check8"

Code something like this should do:

Sub ScratchMacro()
Dim oFFs As FormFields
Dim i As Long
Dim pStr As String
Dim pTempStr As String
Set oFFs = ActiveDocument.FormFields
For i = 1 To 8
If oFFs("Check" & i).CheckBox.Value = True Then
pStr = pStr & Choose(i, "A", "B", "C", "D", "E", "F", "G", "H") & ", "
End If
Next i
pStr = Left(pStr, Len(pStr) - 2)
i = InStrRev(pStr, ",")
pTempStr = Right(pStr, Len(pStr) - i)
pStr = Left(pStr, i - 1)
pStr = pStr & " and" & pTempStr
MsgBox pStr
End Sub

trance4mason@gmail.com wrote:
> Hiya - first post alert!
>
> I'm try to get word to form a sentence from user selected checkboxes,
> for example a user selects the items that they want and then word
> forms a sentence such as "i want X, Y and Z" So that it inserts commas
> and the word "and" in the correct place.
>
> i tried having a count, for the items and then when the count is > 1
> getting word to type ", " but this code never called.
>
> any help please?



Re: Forming a sentence from a checkbox list by Gregory

Gregory
Fri Jul 11 19:31:52 PDT 2008

Allow me to refine that code a bit. I discovered that the string
manipulation could be done with fewer steps but regardless it would throw an
error if only one box where checked. This seems to work better:

Sub ScratchMacroII()
Dim oFFs As FormFields
Dim i As Long
Dim pStr As String
Set oFFs = ActiveDocument.FormFields
For i = 1 To 8
If oFFs("Check" & i).CheckBox.Value = True Then
pStr = pStr & Choose(i, "A", "B", "C", "D", "E", "F", "G", "H") & ", "
End If
Next i
pStr = Left(pStr, Len(pStr) - 2)
On Error Resume Next
pStr = Left(pStr, InStrRev(pStr, ",") - 1) & " and" & Mid(pStr,
InStrRev(pStr, ",") + 1)
On Error GoTo 0
pStr = pStr
MsgBox pStr
End Sub

Gregory K. Maxey wrote:
> Lets assume that you are talking about formfield checkboxes in a
> protected document.
>
> I created 8 checkboxes bookmarked "Check1" through "Check8"
>
> Code something like this should do:
>
> Sub ScratchMacro()
> Dim oFFs As FormFields
> Dim i As Long
> Dim pStr As String
> Dim pTempStr As String
> Set oFFs = ActiveDocument.FormFields
> For i = 1 To 8
> If oFFs("Check" & i).CheckBox.Value = True Then
> pStr = pStr & Choose(i, "A", "B", "C", "D", "E", "F", "G", "H") &
> ", " End If
> Next i
> pStr = Left(pStr, Len(pStr) - 2)
> i = InStrRev(pStr, ",")
> pTempStr = Right(pStr, Len(pStr) - i)
> pStr = Left(pStr, i - 1)
> pStr = pStr & " and" & pTempStr
> MsgBox pStr
> End Sub
>
> trance4mason@gmail.com wrote:
>> Hiya - first post alert!
>>
>> I'm try to get word to form a sentence from user selected checkboxes,
>> for example a user selects the items that they want and then word
>> forms a sentence such as "i want X, Y and Z" So that it inserts
>> commas and the word "and" in the correct place.
>>
>> i tried having a count, for the items and then when the count is > 1
>> getting word to type ", " but this code never called.
>>
>> any help please?