GenuineGin
01-30-2015, 03:48 AM
Hello,
I am trying to insert autotext into a report based on the selections in a multiselect listbox.
The items include: Bat - Building, Bat - Tree, Badger, Otter, Dormouse etc.
Bat - Building is item(1), Bat - Tree is item(2), the rest are item(3) onwards and are all classed as 'other'.
'Insert Appropriate Criteria Table
Dim CriteriaTableRng As Range
'All
If lstPh1SppSurveyed.Selected(1) = True And lstPh1SppSurveyed.Selected(2) = True Then
If lstPh1SppSurveyed.Selected(3) = True Or lstPh1SppSurveyed.Selected(4) = True Or lstPh1SppSurveyed.Selected(5) = True Or lstPh1SppSurveyed.Selected(6) = True Or _
lstPh1SppSurveyed.Selected(7) = True Or lstPh1SppSurveyed.Selected(8) = True Or lstPh1SppSurveyed.Selected(9) = True _
Or lstPh1SppSurveyed.Selected(10) = True Or lstPh1SppSurveyed.Selected(11) = True Or lstPh1SppSurveyed.Selected(12) = True Then
Set CriteriaTableRng = ActiveDocument.Bookmarks("CriteriaTable").Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Criteria Table - All").Insert Where:=CriteriaTableRng, RichText:=True
End If
End If
'Bat Building and Other
If lstPh1SppSurveyed.Selected(2) = False And lstPh1SppSurveyed.Selected(1) = True Then
If lstPh1SppSurveyed.Selected(3) = True Or lstPh1SppSurveyed.Selected(4) = True Or lstPh1SppSurveyed.Selected(5) = True Or _
lstPh1SppSurveyed.Selected(6) = True Or lstPh1SppSurveyed.Selected(7) = True Or lstPh1SppSurveyed.Selected(8) = True Or lstPh1SppSurveyed.Selected(9) = True _
Or lstPh1SppSurveyed.Selected(10) = True Or lstPh1SppSurveyed.Selected(11) = True Or lstPh1SppSurveyed.Selected(12) = True Then
Set CriteriaTableRng = ActiveDocument.Bookmarks("CriteriaTable").Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Criteria Table - Bat Bld & Other").Insert Where:=CriteriaTableRng, RichText:=True
End If
End If
'Bat Tree and Other
If lstPh1SppSurveyed.Selected(1) = False And lstPh1SppSurveyed.Selected(2) = True Then
If lstPh1SppSurveyed.Selected(3) = True Or lstPh1SppSurveyed.Selected(4) = True Or lstPh1SppSurveyed.Selected(5) = True Or _
lstPh1SppSurveyed.Selected(6) = True Or lstPh1SppSurveyed.Selected(7) = True Or lstPh1SppSurveyed.Selected(8) = True Or lstPh1SppSurveyed.Selected(9) = True _
Or lstPh1SppSurveyed.Selected(10) = True Or lstPh1SppSurveyed.Selected(11) = True Or lstPh1SppSurveyed.Selected(12) = True Then
Set CriteriaTableRng = ActiveDocument.Bookmarks("CriteriaTable").Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Criteria Table - Tree & Other").Insert Where:=CriteriaTableRng, RichText:=True
End If
End If
'Bat Building and Tree
If lstPh1SppSurveyed.Selected(1) = True And lstPh1SppSurveyed.Selected(2) = True Then
If lstPh1SppSurveyed.Selected(3) = False And lstPh1SppSurveyed.Selected(4) = False And lstPh1SppSurveyed.Selected(5) = False And lstPh1SppSurveyed.Selected(6) = False And _
lstPh1SppSurveyed.Selected(7) = False And lstPh1SppSurveyed.Selected(8) = False And lstPh1SppSurveyed.Selected(9) = False And _
lstPh1SppSurveyed.Selected(10) = False And lstPh1SppSurveyed.Selected(11) = False And lstPh1SppSurveyed.Selected(12) = False Then
Set CriteriaTableRng = ActiveDocument.Bookmarks("CriteriaTable").Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Criteria Table - Bat Bld & Tree").Insert Where:=CriteriaTableRng, RichText:=True
End If
End If
'Bat Building Only
If lstPh1SppSurveyed.Selected(1) = True Then
If lstPh1SppSurveyed.Selected(2) = False And lstPh1SppSurveyed.Selected(3) = False And lstPh1SppSurveyed.Selected(4) = False And _
lstPh1SppSurveyed.Selected(5) = False And lstPh1SppSurveyed.Selected(6) = False And lstPh1SppSurveyed.Selected(7) = False And lstPh1SppSurveyed.Selected(8) = False And lstPh1SppSurveyed.Selected(9) = False _
Or lstPh1SppSurveyed.Selected(10) = False And lstPh1SppSurveyed.Selected(11) = False And lstPh1SppSurveyed.Selected(12) = False Then
Set CriteriaTableRng = ActiveDocument.Bookmarks("CriteriaTable").Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Criteria Table - Bat Bld").Insert Where:=CriteriaTableRng, RichText:=True
End If
End If
'Bat Tree Only
If lstPh1SppSurveyed.Selected(2) = True Then
If lstPh1SppSurveyed.Selected(1) = False And lstPh1SppSurveyed.Selected(3) = False And lstPh1SppSurveyed.Selected(4) = False And _
lstPh1SppSurveyed.Selected(5) = False And lstPh1SppSurveyed.Selected(6) = False And lstPh1SppSurveyed.Selected(7) = False And lstPh1SppSurveyed.Selected(8) = False And lstPh1SppSurveyed.Selected(9) = False _
And lstPh1SppSurveyed.Selected(10) = False And lstPh1SppSurveyed.Selected(11) = False And lstPh1SppSurveyed.Selected(12) = False Then
Set CriteriaTableRng = ActiveDocument.Bookmarks("CriteriaTable").Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Criteria Table - Tree").Insert Where:=CriteriaTableRng, RichText:=True
End If
End If
'Other Only
If lstPh1SppSurveyed.Selected(1) = False And lstPh1SppSurveyed.Selected(2) = False Then
If lstPh1SppSurveyed.Selected(3) = True Or lstPh1SppSurveyed.Selected(4) = True Or _
lstPh1SppSurveyed.Selected(5) = True Or lstPh1SppSurveyed.Selected(6) = True Or lstPh1SppSurveyed.Selected(7) = True Or lstPh1SppSurveyed.Selected(8) = True Or lstPh1SppSurveyed.Selected(9) = True _
Or lstPh1SppSurveyed.Selected(10) = True Or lstPh1SppSurveyed.Selected(11) = True Or lstPh1SppSurveyed.Selected(12) = True Then
Set CriteriaTableRng = ActiveDocument.Bookmarks("CriteriaTable").Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Criteria Table - Other").Insert Where:=CriteriaTableRng, RichText:=True
End If
End If
The code seems to work for everything except when there is a combination including "Bat - Building" (Item(1)), then the "Bat - Building" bit supersedes everything else (I.e. Bat - Building = correct, Bat - Tree and Other = Correct, Bat - Building and Bat - Tree = Bat - Building, Bat - Building and Other = Bat - Building). My question is why?
Bit of a mind bender but I hope that makes sense...
Gin
I am trying to insert autotext into a report based on the selections in a multiselect listbox.
The items include: Bat - Building, Bat - Tree, Badger, Otter, Dormouse etc.
Bat - Building is item(1), Bat - Tree is item(2), the rest are item(3) onwards and are all classed as 'other'.
'Insert Appropriate Criteria Table
Dim CriteriaTableRng As Range
'All
If lstPh1SppSurveyed.Selected(1) = True And lstPh1SppSurveyed.Selected(2) = True Then
If lstPh1SppSurveyed.Selected(3) = True Or lstPh1SppSurveyed.Selected(4) = True Or lstPh1SppSurveyed.Selected(5) = True Or lstPh1SppSurveyed.Selected(6) = True Or _
lstPh1SppSurveyed.Selected(7) = True Or lstPh1SppSurveyed.Selected(8) = True Or lstPh1SppSurveyed.Selected(9) = True _
Or lstPh1SppSurveyed.Selected(10) = True Or lstPh1SppSurveyed.Selected(11) = True Or lstPh1SppSurveyed.Selected(12) = True Then
Set CriteriaTableRng = ActiveDocument.Bookmarks("CriteriaTable").Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Criteria Table - All").Insert Where:=CriteriaTableRng, RichText:=True
End If
End If
'Bat Building and Other
If lstPh1SppSurveyed.Selected(2) = False And lstPh1SppSurveyed.Selected(1) = True Then
If lstPh1SppSurveyed.Selected(3) = True Or lstPh1SppSurveyed.Selected(4) = True Or lstPh1SppSurveyed.Selected(5) = True Or _
lstPh1SppSurveyed.Selected(6) = True Or lstPh1SppSurveyed.Selected(7) = True Or lstPh1SppSurveyed.Selected(8) = True Or lstPh1SppSurveyed.Selected(9) = True _
Or lstPh1SppSurveyed.Selected(10) = True Or lstPh1SppSurveyed.Selected(11) = True Or lstPh1SppSurveyed.Selected(12) = True Then
Set CriteriaTableRng = ActiveDocument.Bookmarks("CriteriaTable").Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Criteria Table - Bat Bld & Other").Insert Where:=CriteriaTableRng, RichText:=True
End If
End If
'Bat Tree and Other
If lstPh1SppSurveyed.Selected(1) = False And lstPh1SppSurveyed.Selected(2) = True Then
If lstPh1SppSurveyed.Selected(3) = True Or lstPh1SppSurveyed.Selected(4) = True Or lstPh1SppSurveyed.Selected(5) = True Or _
lstPh1SppSurveyed.Selected(6) = True Or lstPh1SppSurveyed.Selected(7) = True Or lstPh1SppSurveyed.Selected(8) = True Or lstPh1SppSurveyed.Selected(9) = True _
Or lstPh1SppSurveyed.Selected(10) = True Or lstPh1SppSurveyed.Selected(11) = True Or lstPh1SppSurveyed.Selected(12) = True Then
Set CriteriaTableRng = ActiveDocument.Bookmarks("CriteriaTable").Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Criteria Table - Tree & Other").Insert Where:=CriteriaTableRng, RichText:=True
End If
End If
'Bat Building and Tree
If lstPh1SppSurveyed.Selected(1) = True And lstPh1SppSurveyed.Selected(2) = True Then
If lstPh1SppSurveyed.Selected(3) = False And lstPh1SppSurveyed.Selected(4) = False And lstPh1SppSurveyed.Selected(5) = False And lstPh1SppSurveyed.Selected(6) = False And _
lstPh1SppSurveyed.Selected(7) = False And lstPh1SppSurveyed.Selected(8) = False And lstPh1SppSurveyed.Selected(9) = False And _
lstPh1SppSurveyed.Selected(10) = False And lstPh1SppSurveyed.Selected(11) = False And lstPh1SppSurveyed.Selected(12) = False Then
Set CriteriaTableRng = ActiveDocument.Bookmarks("CriteriaTable").Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Criteria Table - Bat Bld & Tree").Insert Where:=CriteriaTableRng, RichText:=True
End If
End If
'Bat Building Only
If lstPh1SppSurveyed.Selected(1) = True Then
If lstPh1SppSurveyed.Selected(2) = False And lstPh1SppSurveyed.Selected(3) = False And lstPh1SppSurveyed.Selected(4) = False And _
lstPh1SppSurveyed.Selected(5) = False And lstPh1SppSurveyed.Selected(6) = False And lstPh1SppSurveyed.Selected(7) = False And lstPh1SppSurveyed.Selected(8) = False And lstPh1SppSurveyed.Selected(9) = False _
Or lstPh1SppSurveyed.Selected(10) = False And lstPh1SppSurveyed.Selected(11) = False And lstPh1SppSurveyed.Selected(12) = False Then
Set CriteriaTableRng = ActiveDocument.Bookmarks("CriteriaTable").Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Criteria Table - Bat Bld").Insert Where:=CriteriaTableRng, RichText:=True
End If
End If
'Bat Tree Only
If lstPh1SppSurveyed.Selected(2) = True Then
If lstPh1SppSurveyed.Selected(1) = False And lstPh1SppSurveyed.Selected(3) = False And lstPh1SppSurveyed.Selected(4) = False And _
lstPh1SppSurveyed.Selected(5) = False And lstPh1SppSurveyed.Selected(6) = False And lstPh1SppSurveyed.Selected(7) = False And lstPh1SppSurveyed.Selected(8) = False And lstPh1SppSurveyed.Selected(9) = False _
And lstPh1SppSurveyed.Selected(10) = False And lstPh1SppSurveyed.Selected(11) = False And lstPh1SppSurveyed.Selected(12) = False Then
Set CriteriaTableRng = ActiveDocument.Bookmarks("CriteriaTable").Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Criteria Table - Tree").Insert Where:=CriteriaTableRng, RichText:=True
End If
End If
'Other Only
If lstPh1SppSurveyed.Selected(1) = False And lstPh1SppSurveyed.Selected(2) = False Then
If lstPh1SppSurveyed.Selected(3) = True Or lstPh1SppSurveyed.Selected(4) = True Or _
lstPh1SppSurveyed.Selected(5) = True Or lstPh1SppSurveyed.Selected(6) = True Or lstPh1SppSurveyed.Selected(7) = True Or lstPh1SppSurveyed.Selected(8) = True Or lstPh1SppSurveyed.Selected(9) = True _
Or lstPh1SppSurveyed.Selected(10) = True Or lstPh1SppSurveyed.Selected(11) = True Or lstPh1SppSurveyed.Selected(12) = True Then
Set CriteriaTableRng = ActiveDocument.Bookmarks("CriteriaTable").Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Criteria Table - Other").Insert Where:=CriteriaTableRng, RichText:=True
End If
End If
The code seems to work for everything except when there is a combination including "Bat - Building" (Item(1)), then the "Bat - Building" bit supersedes everything else (I.e. Bat - Building = correct, Bat - Tree and Other = Correct, Bat - Building and Bat - Tree = Bat - Building, Bat - Building and Other = Bat - Building). My question is why?
Bit of a mind bender but I hope that makes sense...
Gin