Parameter based field names

J

Jim gardner

This must be simple but how do I use a variable to refer
to multiple fields? I have a user form with many check
boxes (eg CheckBox1, CheckBox2....etc). I want to test if
any of them has been checked within a loop eg

For i = 1 to 20
If CheckBox & i = True then etc etc
End if
Next i

What syntax do I need? I can't find any reference in the
online help. I tried using the syntax shown above but it
seems that the expression evaluates to True for every
occurrence of "i" even when I only tick one box!

Many thanks

Jim
 
H

Helmut Weber

Hi Jim,
unfortunately I can't see a way to create an array
of checkboxes in VBA, opposite to VB. Nevertheless,
if your checkboxes have systematical names, you
can address them programmatically. The following example
deals with formfields (checkboxes) in a table,
which were named according to row and column (RxCy).
Dim oFrm As FormField
For Each oFrm In ActiveDocument.FormFields
If oFrm.name = "R3C3" Then
Stop
End If
Next

Hope it helps.

Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, Win 98
 
C

Cindy Meister -WordMVP-

Hi Jim,

I think you'll find an article on this on the mvps.org/word
site, but just in case there isn't one, very briefly:

szControl = "Checkbox" & CStr(i)
If Me.Controls(szControl).Value = True Then
This must be simple but how do I use a variable to refer
to multiple fields? I have a user form with many check
boxes (eg CheckBox1, CheckBox2....etc). I want to test if
any of them has been checked within a loop eg

For i = 1 to 20
If CheckBox & i = True then etc etc
End if
Next i

What syntax do I need?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan
24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 
J

Jim Gardner

Hi Cindy

Brilliant! You've been a big help. By the way I tried
searching the online help file in VBA for ages but could
not find the answer to this problem. The online help is
good for looking up the syntax of commands etc but for
something like this I was stumped! Any ideas what I
should have searched for?

Kind Regards

Jim
 
C

Cindy Meister -WordMVP-

Hi Jim,
By the way I tried
searching the online help file in VBA for ages but could
not find the answer to this problem. The online help is
good for looking up the syntax of commands etc but for
something like this I was stumped! Any ideas what I
should have searched for?
Not really, no. The on-line Help isn't really meant to be
anything more than syntax + basic useage. For more than
that - for the problem solutions - the next place to start
looking would be the msdn site and the Knowledge Base on
microsoft.com.

After that, mvps.org/word and the other website maintained
by MVPs and regulars in this newsgroup (and maybe
wopr.com).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jan 24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

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