INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Word VBA - finding which order checkboxes are selected

Word VBA - finding which order checkboxes are selected

(OP)
Hi there, I have a form which has a number of checkboxes. Is it possible to capture and store the order in which the checkboxes were selected in an array?

So if there are 20 checkboxes and the user selects CheckBox1, CheckBox3, Checkbox18, I want to capture the Control.Value (which I assume is the Checkbox name) and place into an array in the same order it was selected

The code so far is:

CODE

Dim Ctl As Control
           For Each Ctl In DocProperties.Controls
            If TypeOf Ctl Is MSForms.CheckBox Then
                If Ctl Then ChkCount = ChkCount + 1
                        If Ctl.Value = True Then
                            ReDim Preserve myArray(ChkCount)
                            myArray(ChkCount) = Ctl.Caption
                            
                        End If
                End If
            Next 

RE: Word VBA - finding which order checkboxes are selected

A VBA userform or a Word document?

RE: Word VBA - finding which order checkboxes are selected

(OP)
Sorry, a VBA Userform in Word.

Cheers
Steve

RE: Word VBA - finding which order checkboxes are selected

What happens when the user checks/unchecks the same checkbox multiple times?

Cheers
Paul Edstein
[MS MVP - Word]

RE: Word VBA - finding which order checkboxes are selected

Here's one example, which assumes that the last time an item is checked defines where it appears in the order (given macropod's apt question).It assumes you have a user form with several checkboxes, a command button and a listbox:

CODE

Option Explicit

Public CheckArray As New Collection

Private Sub CheckBox1_Click()
    CheckMe ActiveControl
End Sub

Private Sub CheckBox2_Click()
    CheckMe ActiveControl
End Sub

Private Sub CheckBox3_Click()
    CheckMe ActiveControl
End Sub

Private Sub CheckBox4_Click()
    CheckMe ActiveControl
End Sub

Private Sub CommandButton1_Click()
    Dim myControl
    ListBox1.Clear
    For Each myControl In CheckArray
        ListBox1.AddItem myControl.Name
    Next
End Sub

Public Sub CheckMe(chkbox As Control)
    If chkbox = True Then
        CheckArray.Add chkbox, chkbox.Name
    Else
        CheckArray.Remove chkbox.Name
    End If
End Sub 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close