Below is a section of my macro. Is there a way to do a loop?

Dim i as Long
Dim WC35 As String, WC36 As String, WC37 As String

Set oFF = ActiveDocument.FormFields

If oFF("Check35").CheckBox.Value = False And Me.Controls("Ck35").Value =
False Then
WC35 = False
ElseIf oFF("Check35").CheckBox.Value = False And Me.Controls("Ck35").Value =
True Then
WC35 = False
ElseIf oFF("Check35").CheckBox.Value = True And Me.Controls("Ck35").Value =
False Then
WC35 = True
ElseIf oFF("Check35").CheckBox.Value = True And Me.Controls("Ck35").Value =
True Then
WC35 = False
End If

If oFF("Check36").CheckBox.Value = False And Me.Controls("Ck36").Value =
False Then
WC36 = False
ElseIf oFF("Check36").CheckBox.Value = False And Me.Controls("Ck36").Value =
True Then
WC36 = False
ElseIf oFF("Check36").CheckBox.Value = True And Me.Controls("Ck36").Value =
False Then
WC36 = True
ElseIf oFF("Check36").CheckBox.Value = True And Me.Controls("Ck36").Value =
True Then
WC36 = False
End If

If oFF("Check37").CheckBox.Value = False And Me.Controls("Ck37").Value =
False Then
WC37 = False
ElseIf oFF("Check37").CheckBox.Value = False And Me.Controls("Ck37").Value =
True Then
WC37 = False
ElseIf oFF("Check37").CheckBox.Value = True And Me.Controls("Ck37").Value =
False Then
WC37 = True
ElseIf oFF("Check37").CheckBox.Value = True And Me.Controls("Ck37").Value =
True Then
WC37 = False
End If
Set oFF = Nothing



I tried the following but the debugger kept giving me an error at â??(â??WCâ?? &
i)â??.

Set oFF = ActiveDocument.FormFields
For i = 35 To 37
If oFF("Check" & i).CheckBox.Value = False And Me.Controls("Ck" & i).Value =
False Then
(â??WCâ?? & i) = False
ElseIf oFF("Check" & i).CheckBox.Value = False And Me.Controls("Ck" &
i).Value = True Then
(â??WCâ?? & i) = False
ElseIf oFF("Check" & i).CheckBox.Value = True And Me.Controls("Ck" &
i).Value = False Then
(â??WCâ?? & i) = True
ElseIf oFF("Check" & i).CheckBox.Value = True And Me.Controls("Ck" &
i).Value = True Then
(â??WCâ?? & i) = False
End If
Next i
Set oFF = Nothing

Re: Working with Loops by Helmut

Helmut
Sat Jan 12 14:40:09 PST 2008

Hi LEU,

try CStr(i): (?WC? & Cstr(i))



--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Re: Working with Loops by Helmut

Helmut
Sat Jan 12 14:43:46 PST 2008

... also:

compare:
>try CStr(i): (?WC? & Cstr(i))
vs
>try CStr(i): ("WC" & Cstr(i))


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Re: Working with Loops by LEU

LEU
Sat Jan 12 15:26:00 PST 2008

Hi Helmut,

These both look the same. I plugged it into my macro as follows and I get an
error 'Syntax error'.

Set oFF = ActiveDocument.FormFields
For i = 35 To 37
If oFF("Checki").CheckBox.Value = False And Me.Controls("Cki").Value = False
Then
CStr(i): (â??WCâ?? & Cstr(i)) = false
ElseIf oFF("Checki").CheckBox.Value = False And Me.Controls("Cki").Value =
True Then
CStr(i): (â??WCâ?? & Cstr(i)) = false
ElseIf oFF("Checki").CheckBox.Value = True And Me.Controls("Cki").Value =
False Then
CStr(i): (â??WCâ?? & Cstr(i)) = true
ElseIf oFF("Checki").CheckBox.Value = True And Me.Controls("Cki").Value =
True Then
CStr(i): (â??WCâ?? & Cstr(i)) = false
End If
Next i



"Helmut Weber" wrote:

> .... also:
>
> compare:
> >try CStr(i): (â??WCâ?? & Cstr(i))
> vs
> >try CStr(i): ("WC" & Cstr(i))
>
>
> --
>
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Vista Small Business, Office XP
>

Re: Working with Loops by LEU

LEU
Sat Jan 12 15:45:02 PST 2008

It really looks like this:

Set oFF = ActiveDocument.FormFields
For i = 35 To 37
If oFF("Check" & i).CheckBox.Value = False _
And Me.Controls("Ck" & i).Value = False Then
CStr(i): (â??WCâ?? & Cstr(i)) = false
ElseIf oFF("Check" & i).CheckBox.Value = False _
And Me.Controls("Ck" & i).Value = True Then
CStr(i): (â??WCâ?? & Cstr(i)) = false
ElseIf oFF("Check" & i).CheckBox.Value = True _
And Me.Controls("Ck" & i).Value = False Then
CStr(i): (â??WCâ?? & Cstr(i)) = true
ElseIf oFF("Check" & i).CheckBox.Value = True _
And Me.Controls("Ck" & i).Value = True Then
CStr(i): (â??WCâ?? & Cstr(i)) = false
End If
Next i



"LEU" wrote:

> Hi Helmut,
>
> These both look the same. I plugged it into my macro as follows and I get an
> error 'Syntax error'.
>
> Set oFF = ActiveDocument.FormFields
> For i = 35 To 37
> If oFF("Checki").CheckBox.Value = False And Me.Controls("Cki").Value = False
> Then
> CStr(i): (â??WCâ?? & Cstr(i)) = false
> ElseIf oFF("Checki").CheckBox.Value = False And Me.Controls("Cki").Value =
> True Then
> CStr(i): (â??WCâ?? & Cstr(i)) = false
> ElseIf oFF("Checki").CheckBox.Value = True And Me.Controls("Cki").Value =
> False Then
> CStr(i): (â??WCâ?? & Cstr(i)) = true
> ElseIf oFF("Checki").CheckBox.Value = True And Me.Controls("Cki").Value =
> True Then
> CStr(i): (â??WCâ?? & Cstr(i)) = false
> End If
> Next i
>
>
>
> "Helmut Weber" wrote:
>
> > .... also:
> >
> > compare:
> > >try CStr(i): (â??WCâ?? & Cstr(i))
> > vs
> > >try CStr(i): ("WC" & Cstr(i))
> >
> >
> > --
> >
> > Greetings from Bavaria, Germany
> >
> > Helmut Weber, MVP WordVBA
> >
> > Vista Small Business, Office XP
> >

Re: Working with Loops by Helmut

Helmut
Sat Jan 12 15:54:36 PST 2008

Hi LEU,

sorry, you are completely off the track.

>If oFF("Checki").CheckBox.Value = False And Me.Controls("Cki").Value = False
>Then
> CStr(i): (?WC? & Cstr(i)) = false
>ElseIf oFF("Checki").CheckBox.Value = False And Me.Controls("Cki").Value =

"Checki" doesn't make sense.
"Check" & Cstr(i) '!
"Cki" doesn't make sense either.
"Ck" & Cstr(i) '!

You might be better off with a "select case" command.




--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Re: Working with Loops by LEU

LEU
Sat Jan 12 16:26:00 PST 2008

What I tried really looks like this:

Set oFF = ActiveDocument.FormFields
For i = 35 To 37
If oFF("Check" & i).CheckBox.Value = False _
And Me.Controls("Ck" & i).Value = False Then
CStr(i): (â??WCâ?? & Cstr(i)) = false
ElseIf oFF("Check" & i).CheckBox.Value = False _
And Me.Controls("Ck" & i).Value = True Then
CStr(i): (â??WCâ?? & Cstr(i)) = false
ElseIf oFF("Check" & i).CheckBox.Value = True _
And Me.Controls("Ck" & i).Value = False Then
CStr(i): (â??WCâ?? & Cstr(i)) = true
ElseIf oFF("Check" & i).CheckBox.Value = True _
And Me.Controls("Ck" & i).Value = True Then
CStr(i): (â??WCâ?? & Cstr(i)) = false
End If
Next i

The ("Ck" & i) are the check boxes in my form.

LEU


"Helmut Weber" wrote:

> Hi LEU,
>
> sorry, you are completely off the track.
>
> >If oFF("Checki").CheckBox.Value = False And Me.Controls("Cki").Value = False
> >Then
> > CStr(i): (â??WCâ?? & Cstr(i)) = false
> >ElseIf oFF("Checki").CheckBox.Value = False And Me.Controls("Cki").Value =
>
> "Checki" doesn't make sense.
> "Check" & Cstr(i) '!
> "Cki" doesn't make sense either.
> "Ck" & Cstr(i) '!
>
> You might be better off with a "select case" command.
>
>
>
>
> --
>
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Vista Small Business, Office XP
>

Re: Working with Loops by Helmut

Helmut
Sun Jan 13 03:46:50 PST 2008

Hi LEU,

apart from other issues,

>If oFF("Check" & i).CheckBox.Value = False
^ ^
Check is enclosed in straight quotes chr(34), that is ok!

> CStr(i): (?WC? & Cstr(i)) = false
^ ^
WC is preceded by chr(147) and followed by chr(148), that is not ok!

Furthermore don't try to assign a boolean value to a string,
like (?WC? & Cstr(i)) = false

Use a nonproportional font such as CourierNew
to display this message.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP