#1   Report Post  
Posted to microsoft.public.word.docmanagement
owen owen is offline
external usenet poster
 
Posts: 61
Default Form Checkbox

I am wondering if it is possible to use a For...Next method on a UserForm
which contains 13 checkboxes, where i need to evaluate and If/Then/Else
statement.

For example, currently my If/Then/Else works by evaluating each of the 13
checkboxes separately which makes for a lot of code.ie

If UserForm1.CheckBox1.value = True Then
....
....
Else
If UserForm1.CheckBox2.value = True Then etc

Can i use a For Next method along the lines of
For j= 1 to 13
If UserForm1.Checkbox(j).value = True Then
....
End If
Next J

Not sure if this is possible but would appreciate any help so i can reduce
the amount of code i need to reproduce.

Thanks
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Form Checkbox

If all the checkboxes are named with the same beginning part plus a number (like
the default names CheckBox1, CheckBox2, etc.), you can form a string containing
the name and use that as the "index" into the UserForm's Controls collection:

Dim j As Integer
For j = 1 To 3
If Me.Controls("CheckBox" & j).Value Then
MsgBox "CheckBox" & j & " is checked"
End If
Next

If you would rather name the checkboxes according to their meanings (which is
usually advisable), then you can loop through the whole Controls collection and
pick out just the checkboxes.

Dim ctl As Control
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then
If ctl.Value Then
MsgBox ctl.Name & " is checked"
End If
End If
Next

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.

On Sat, 18 Jul 2009 07:11:01 -0700, Owen wrote:

I am wondering if it is possible to use a For...Next method on a UserForm
which contains 13 checkboxes, where i need to evaluate and If/Then/Else
statement.

For example, currently my If/Then/Else works by evaluating each of the 13
checkboxes separately which makes for a lot of code.ie

If UserForm1.CheckBox1.value = True Then
...
...
Else
If UserForm1.CheckBox2.value = True Then etc

Can i use a For Next method along the lines of
For j= 1 to 13
If UserForm1.Checkbox(j).value = True Then
...
End If
Next J

Not sure if this is possible but would appreciate any help so i can reduce
the amount of code i need to reproduce.

Thanks

  #3   Report Post  
Posted to microsoft.public.word.docmanagement
owen owen is offline
external usenet poster
 
Posts: 61
Default Form Checkbox

Thanks Jay, that is awesome.

"Jay Freedman" wrote:

If all the checkboxes are named with the same beginning part plus a number (like
the default names CheckBox1, CheckBox2, etc.), you can form a string containing
the name and use that as the "index" into the UserForm's Controls collection:

Dim j As Integer
For j = 1 To 3
If Me.Controls("CheckBox" & j).Value Then
MsgBox "CheckBox" & j & " is checked"
End If
Next

If you would rather name the checkboxes according to their meanings (which is
usually advisable), then you can loop through the whole Controls collection and
pick out just the checkboxes.

Dim ctl As Control
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then
If ctl.Value Then
MsgBox ctl.Name & " is checked"
End If
End If
Next

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.

On Sat, 18 Jul 2009 07:11:01 -0700, Owen wrote:

I am wondering if it is possible to use a For...Next method on a UserForm
which contains 13 checkboxes, where i need to evaluate and If/Then/Else
statement.

For example, currently my If/Then/Else works by evaluating each of the 13
checkboxes separately which makes for a lot of code.ie

If UserForm1.CheckBox1.value = True Then
...
...
Else
If UserForm1.CheckBox2.value = True Then etc

Can i use a For Next method along the lines of
For j= 1 to 13
If UserForm1.Checkbox(j).value = True Then
...
End If
Next J

Not sure if this is possible but would appreciate any help so i can reduce
the amount of code i need to reproduce.

Thanks


Reply
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
Checkbox form field SLEE Microsoft Word Help 4 June 10th 09 11:49 PM
How do I protect the checkbox in my form mike New Users 5 October 8th 08 11:26 AM
Form fields: IF (checkbox)? Mike Microsoft Word Help 2 April 29th 06 01:10 PM
Form Field Checkbox Peggy Microsoft Word Help 1 March 2nd 06 10:33 AM
IF THEN ELSE with FORM CHECKBOX Jane Mailmerge 1 March 25th 05 07:55 AM


All times are GMT +1. The time now is 06:50 PM.

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"