I am working on a listbox that pulls information from a table in another word document. Currently, the connection between the parent document listbox and the tabe is working (the listbox populates properly), and the document variables are populated correctly. In short it's working fine with the listbox set to accept single selections.
What I'd like to have is the first listbox open to multiple selections, however, I'm having trouble with the code to transfer multiselections to the variables in the document upon execution of the OK command button. I assume I need some sort of a loop to do this. The table has only two columns and a variable number of rows.
I am adapting code found in a FAQ by Greg Maxey which has been very helpful (Thanks Greg).
Here's the code for the OK button:
Code:
Private Sub CommandButton1_Click() 'Continue button
Set oTarget = ActiveDocument
Set oVars = oTarget.Variables
'Ensure that selections have been made and if not warn the user.
If Me.ListBox1.ListIndex = -1 Or Me.ListBox2.ListIndex = -1 Then
MsgBox "Selections incomplete!"
Exit Sub
End If
'Insert code that detects multiple selections and transfers output to variables
'Add the values of the list boxes to the variables
oVars("Citation").Value = Me.ListBox1.Column(0)
oVars("Violation").Value = Me.ListBox1.Column(1)
oVars("User").Value = Me.ListBox2.Column(0)
oVars("Title").Value = Me.ListBox2.Column(1)
oTarget.Fields.Update
'Update the fields in the document, to display the new content of the docvariable fields.
Unload Me
End Sub
Thanks!