Template with Conditional Formating

R

Rand8203

I am looking to create a template or form in Word 2003 that will contain a
variable number of items each with a drop down list. For example...

Body Text

Exhibit A: Drop Down List
....
Exhibit N: Drop Down List

Body Text

The drop down list for each exhibit will be the same, but the drop down item
selected for first exhibit would be different from the next. I want a way
for the user to indicate what their last exhibit will be (any letter A-N),
lets say 'D' and then only have Exhibits A through D be available. Also,
when the template is printed then only the relevant exhibits and body text
should print. Any help would be appreciated.
 
G

Gordon Bentley-Mix

Something like the following might work.

This code assumes a UserForm called UserForm1 with five ComboBox controls
called ComboBox1, ComboBox2, ComboBox3, ComboBox4 and ComboBox5, as well as
an 'OK' and a 'Cancel' button. It also assumes five bookmarks in the template
for displaying the results of the ComboBoxes called ExhibitA, ExhibitB,
ExhibitC, ExhibitD and ExhibitE, and five additional bookmarks for
showing/hiding the various "Exhibit" paragraphs called NoExhibitA,
NoExhibitB, NoExhibitC, NoExhibitD and NoExhibitE.

The code in the main module for initiating the process is:

Option Explicit

Public bNewDoc As Boolean
Public myDoc As Document
Public myForm As UserForm1
Dim Combo1Val As String
Dim Combo1Idx As Integer
Dim Combo2Val As String
Dim Combo2Idx As Integer
Dim Combo3Val As String
Dim Combo3Idx As Integer
Dim Combo4Val As String
Dim Combo4Idx As Integer
Dim Combo5Val As String
Dim Combo5Idx As Integer

Sub AutoNew()
Set myDoc = ActiveDocument
Set myForm = New UserForm1
Load myForm
myForm.Show
If bNewDoc = True Then CollectUserFormValues
Unload myForm
Set myForm = Nothing
If bNewDoc Then BuildDoc Else myDoc.Close wdDoNotSaveChanges
End Sub

This code displays an instance of UserForm1, at which point control is
handed over to the UserForm. The code in the UserForm1 module is:

Option Explicit

Dim Combo1Array() As Variant
Dim Combo2Array() As Variant
Dim Combo3Array() As Variant
Dim Combo4Array() As Variant
Dim Combo5Array() As Variant

Sub UserForm_Initialize()
BuildCombo1List
InitializeCombos
End Sub

Sub BuildCombo1List()
Dim i As Integer
Dim ExhibitName As String
ReDim Combo1Array(5) As Variant
Combo1Array(0) = "[SELECT]"
For i = 1 To 5
ExhibitName = "Exhibit " & i
Combo1Array(i) = ExhibitName
Next i
With ComboBox1
.List = Combo1Array
.ListIndex = 0
End With
End Sub

Sub InitializeCombos()
If ComboBox1.ListIndex < 1 Then DisableCombo2 Else EnableCombo2
If ComboBox2.ListIndex < 1 Then DisableCombo3 Else EnableCombo3
If ComboBox3.ListIndex < 1 Then DisableCombo4 Else EnableCombo4
If ComboBox4.ListIndex < 1 Then DisableCombo5 Else EnableCombo5
End Sub

Sub ComboBox1_Change()
If ComboBox1.ListIndex < 1 Then DisableCombo2 Else EnableCombo2
End Sub

Sub DisableCombo2()
With ComboBox2
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
.Clear
End With
End Sub

Sub EnableCombo2()
BuildCombo2List
With ComboBox2
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo2Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo2List()
Dim i As Integer
Dim DelIndex As Integer
ReDim Combo2Array(5) As Variant
DelIndex = ComboBox1.ListIndex
Combo2Array = Combo1Array
If DelIndex <= 4 Then
For i = DelIndex To 4
Combo2Array(i) = Combo2Array(i + 1)
Next i
End If
ReDim Preserve Combo2Array(4) As Variant
End Sub

Sub ComboBox2_Change()
If ComboBox2.ListIndex < 1 Then DisableCombo3 Else EnableCombo3
End Sub

Sub DisableCombo3()
With ComboBox3
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
.Clear
End With
End Sub

Sub EnableCombo3()
BuildCombo3List
With ComboBox3
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo3Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo3List()
Dim i As Integer
Dim DelIndex As Integer
ReDim Combo3Array(4) As Variant
DelIndex = ComboBox2.ListIndex
Combo3Array = Combo2Array
If DelIndex <= 3 Then
For i = DelIndex To 3
Combo3Array(i) = Combo3Array(i + 1)
Next i
End If
ReDim Preserve Combo3Array(3) As Variant
End Sub

Sub ComboBox3_Change()
If ComboBox3.ListIndex < 1 Then DisableCombo4 Else EnableCombo4
End Sub

Sub DisableCombo4()
With ComboBox4
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
.Clear
End With
End Sub

Sub EnableCombo4()
BuildCombo4List
With ComboBox4
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo4Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo4List()
Dim i As Integer
Dim DelIndex As Integer
ReDim Combo4Array(3) As Variant
DelIndex = ComboBox3.ListIndex
Combo4Array = Combo3Array
If DelIndex <= 2 Then
For i = DelIndex To 2
Combo4Array(i) = Combo4Array(i + 1)
Next i
End If
ReDim Preserve Combo4Array(2) As Variant
End Sub

Sub ComboBox4_Change()
If ComboBox4.ListIndex < 1 Then DisableCombo5 Else EnableCombo5
End Sub

Sub DisableCombo5()
With ComboBox5
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
.Clear
End With
End Sub

Sub EnableCombo5()
BuildCombo5List
With ComboBox5
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo5Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo5List()
Dim i As Integer
Dim j As Integer
Dim DelIndex As Integer
ReDim Combo5Array(2) As Variant
DelIndex = ComboBox4.ListIndex
Combo5Array = Combo4Array
If DelIndex <= 1 Then
For i = DelIndex To 1
Combo5Array(i) = Combo5Array(i + 1)
Next i
End If
ReDim Preserve Combo5Array(1) As Variant
End Sub

Sub btnOK_Click()
bNewDoc = True
Me.Hide
End Sub

Sub btnCancel_Click()
Dim myResult As Integer
myResult = MsgBox("Confirm?", vbYesNo, "Cancel")
If myResult = 6 Then
bNewDoc = False
Me.Hide
End If
End Sub

Control is then handed back to the main module and, assuming that the 'OK'
button is clicked, continues as follows:

Sub CollectUserFormValues()
With myForm
With .ComboBox1
Combo1Val = .Value
Combo1Idx = .ListIndex
End With
With .ComboBox2
Combo2Val = .Value
Combo2Idx = .ListIndex
End With
With .ComboBox3
Combo3Val = .Value
Combo3Idx = .ListIndex
End With
With .ComboBox4
Combo4Val = .Value
Combo4Idx = .ListIndex
End With
With .ComboBox5
Combo5Val = .Value
Combo5Idx = .ListIndex
End With
End With
End Sub

Sub BuildDoc()
InsertBookmarkValue "ExhibitA", Combo1Val
If Combo2Idx > 0 Then
ShowBookmarkRange "NoExhibitB"
InsertBookmarkValue "ExhibitB", Combo2Val
Else: HideBookmarkRange "NoExhibitB"
End If
If Combo3Idx > 0 Then
ShowBookmarkRange "NoExhibitC"
InsertBookmarkValue "ExhibitC", Combo3Val
Else: HideBookmarkRange "NoExhibitC"
End If
If Combo4Idx > 0 Then
ShowBookmarkRange "NoExhibitD"
InsertBookmarkValue "ExhibitD", Combo4Val
Else: HideBookmarkRange "NoExhibitD"
End If
If Combo5Idx > 0 Then
ShowBookmarkRange "NoExhibitE"
InsertBookmarkValue "ExhibitE", Combo5Val
Else: HideBookmarkRange "NoExhibitE"
End If
With ActiveWindow.View
.ShowBookmarks = False
.ShowHiddenText = False
.ShowAll = False
End With
End Sub

Sub InsertBookmarkValue(BkmkName As String, Value As String)
With myDoc
If .Bookmarks.Exists(BkmkName) Then
Dim myRange As Range
Set myRange = .Bookmarks(BkmkName).Range
myRange.Text = Value
.Bookmarks.Add BkmkName, myRange
End If
End With
End Sub

Sub ShowBookmarkRange(BkmkName As String)
With myDoc
If .Bookmarks.Exists(BkmkName) Then
..Bookmarks(BkmkName).Range.Font.Hidden = False
End With
End Sub

Sub HideBookmarkRange(BkmkName As String)
With myDoc
If .Bookmarks.Exists(BkmkName) Then
..Bookmarks(BkmkName).Range.Font.Hidden = True
End With
End Sub

See how this works in action, create a template containing a Module and the
UserForm described above, and simply copy and paste this sample code into it
(just be careful of the line breaks that the web interface adds).
Alternatively, you can email me and I'll send you the template.

Note that this code does not quite achieve all of your objectives - it
doesn't have functionality for prompting the user for the last Exhibit and
limiting their choices accordingly, and the names of the Exhibits aren't
quite right - but it was the best I could do in just a couple of hours.
However, I have some time today and will continue working on it. I have an
idea of how to meet all of your goals, but it will take me a bit of time to
get there.

BTW, this is something that I've always wanted to do, so thanks for the
opportunity and motivation. I'm sure it will come in handy for me someday.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
G

Gordon Bentley-Mix

Forgot to add that I won't be able to post the code for prompting the user
and limiting the number of Exhibits until Monday (NZ time). For some reason,
my own computer doesn't play nicely with the forum web interface (IE 7
maybe?), so I have to use a PC at a client site.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
G

Gordon Bentley-Mix

The Full Monty -

Still assuming the same as in my first post - just more: ComboBoxes number 1
through 14 plus a ComboBox (with a Label) for selecting the "last exhibit";
an 'OK' and 'Cancel' button; bookmarks for each ComboBox called "Exhibit1"
through "Exhibit14" and the related "NoExhibit" bookmarks (1 - 14).

Another case of "more of the same" code in the main module, as follows:

Option Explicit

Public bNewDoc As Boolean
Public myDoc As Document
Public myForm As UserForm1
Dim Combo1Val As String
Dim Combo1Idx As Integer
Dim Combo2Val As String
Dim Combo2Idx As Integer
Dim Combo3Val As String
Dim Combo3Idx As Integer
Dim Combo4Val As String
Dim Combo4Idx As Integer
Dim Combo5Val As String
Dim Combo5Idx As Integer
Dim Combo6Val As String
Dim Combo6Idx As Integer
Dim Combo7Val As String
Dim Combo7Idx As Integer
Dim Combo8Val As String
Dim Combo8Idx As Integer
Dim Combo9Val As String
Dim Combo9Idx As Integer
Dim Combo10Val As String
Dim Combo10Idx As Integer
Dim Combo11Val As String
Dim Combo11Idx As Integer
Dim Combo12Val As String
Dim Combo12Idx As Integer
Dim Combo13Val As String
Dim Combo13Idx As Integer
Dim Combo14Val As String
Dim Combo14Idx As Integer

Sub AutoNew()
Set myDoc = ActiveDocument
Set myForm = New UserForm1
Load myForm
myForm.Show
If bNewDoc = True Then CollectUserFormValues
Unload myForm
Set myForm = Nothing
If bNewDoc = True Then BuildDoc Else myDoc.Close wdDoNotSaveChanges
End Sub

And again, control is handed over the the UserForm code when the UserForm is
shown. Lots more code in this module, however, and it will probably require
some explanation.

Option Explicit

Dim LastExhibitIdx As Integer '*** Used to keep track of the "last exhibit"
Dim Combo1Array() As Variant
Dim Combo2Array() As Variant
Dim Combo3Array() As Variant
Dim Combo4Array() As Variant
Dim Combo5Array() As Variant
Dim Combo6Array() As Variant
Dim Combo7Array() As Variant
Dim Combo8Array() As Variant
Dim Combo9Array() As Variant
Dim Combo10Array() As Variant
Dim Combo11Array() As Variant
Dim Combo12Array() As Variant
Dim Combo13Array() As Variant
Dim Combo14Array() As Variant
Dim Combo15Array() As Variant

Sub UserForm_Initialize()
LoadLastExhibitCombo
InitializeCombos
End Sub

Sub LoadLastExhibitCombo()
'***Loads values of "A" to "N" into the ComboBox for the "last exhibit"
Dim myArray As Variant
myArray = Split("[SELECT]|A|B|C|D|E|F|G|H|I|J|K|L|M|N", "|")
With cboLastExhibit
.List = myArray
.ListIndex = 0
End With
End Sub

Sub InitializeCombos()
'***Disables all of the other ComboBoxes - could do this manually but since
there's
' code that does it...
DisableCombo1
DisableCombo2
DisableCombo3
DisableCombo4
DisableCombo5
DisableCombo6
DisableCombo7
DisableCombo8
DisableCombo9
DisableCombo10
DisableCombo11
DisableCombo12
DisableCombo13
DisableCombo14
End Sub

Sub cboLastExhibit_Change()
LastExhibitIdx = cboLastExhibit.ListIndex
ShowExhibitCombos (LastExhibitIdx)
End Sub

Private Sub ShowExhibitCombos(NumberToShow As Integer)
'***Hides/shows the correct number of ComboBoxes depending on the value
' selected for the "last exhibit" ComboBox
ComboBox1.Visible = False
ComboBox2.Visible = False
ComboBox3.Visible = False
ComboBox4.Visible = False
ComboBox5.Visible = False
ComboBox6.Visible = False
ComboBox7.Visible = False
ComboBox8.Visible = False
ComboBox9.Visible = False
ComboBox10.Visible = False
ComboBox11.Visible = False
ComboBox12.Visible = False
ComboBox13.Visible = False
ComboBox14.Visible = False
If NumberToShow > 0 Then
ComboBox1.Visible = True
EnableCombo1
If NumberToShow > 1 Then
ComboBox2.Visible = True
If NumberToShow > 2 Then
ComboBox3.Visible = True
If NumberToShow > 3 Then
ComboBox4.Visible = True
If NumberToShow > 4 Then
ComboBox5.Visible = True
If NumberToShow > 5 Then
ComboBox6.Visible = True
If NumberToShow > 6 Then
ComboBox7.Visible = True
If NumberToShow > 7 Then
ComboBox8.Visible = True
If NumberToShow > 8 Then
ComboBox9.Visible = True
If NumberToShow > 9 Then
ComboBox10.Visible = True
If NumberToShow > 10 Then
ComboBox11.Visible = True
If NumberToShow > 11 Then
ComboBox12.Visible = True
If NumberToShow > 12 Then
ComboBox13.Visible =
True
If NumberToShow > 13
Then

ComboBox14.Visible = True
Else

ComboBox14.Visible = False
End If
Else
ComboBox13.Visible =
False
End If
Else
ComboBox12.Visible = False
End If
Else
ComboBox11.Visible = False
End If
Else
ComboBox10.Visible = False
End If
Else
ComboBox9.Visible = False
End If
Else
ComboBox8.Visible = False
End If
Else
ComboBox7.Visible = False
End If
Else
ComboBox6.Visible = False
End If
Else
ComboBox5.Visible = False
End If
Else
ComboBox4.Visible = False
End If
Else
ComboBox3.Visible = False
End If
Else
ComboBox2.Visible = False
End If
Else
ComboBox1.Visible = False
End If
End Sub

'***Enable, Disable and BuildList procedures for each ComboBox similar to
' previous - just more of 'em; also BuildLists based off the "last
exhibit" value
Sub DisableCombo1()
With ComboBox1
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
.Clear
End With
End Sub

Sub EnableCombo1()
BuildCombo1List
With ComboBox1
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo1Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo1List()
Dim i As Integer
Dim Idx As Integer
Dim ExhibitName As String
Idx = LastExhibitIdx
ReDim Combo1Array(LastExhibitIdx) As Variant
Combo1Array(0) = "[SELECT]"
For i = 1 To Idx
ExhibitName = "Exhibit " & cboLastExhibit.List(i)
Combo1Array(i) = ExhibitName
Next i
With ComboBox1
.List = Combo1Array
.ListIndex = 0
End With
End Sub

Sub ComboBox1_Change()
If ComboBox1.ListIndex < 1 Then DisableCombo2 Else EnableCombo2
End Sub

Sub DisableCombo2()
With ComboBox2
.Clear
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
End With
End Sub

Sub EnableCombo2()
BuildCombo2List
With ComboBox2
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo2Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo2List()
Dim i As Integer
Dim Idx As Integer
Dim DelIndex As Integer
Idx = LastExhibitIdx
ReDim Combo2Array(Idx) As Variant
DelIndex = ComboBox1.ListIndex
Combo2Array = Combo1Array
If DelIndex <= Idx Then
For i = DelIndex To Idx - 1
Combo2Array(i) = Combo2Array(i + 1)
Next i
End If
ReDim Preserve Combo2Array(Idx - 1) As Variant
End Sub

Sub ComboBox2_Change()
If ComboBox2.ListIndex < 1 Then DisableCombo3 Else EnableCombo3
End Sub

Sub DisableCombo3()
With ComboBox3
.Clear
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
End With
End Sub

Sub EnableCombo3()
BuildCombo3List
With ComboBox3
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo3Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo3List()
Dim i As Integer
Dim Idx As Integer
Dim DelIndex As Integer
Idx = LastExhibitIdx - 1
ReDim Combo3Array(Idx) As Variant
DelIndex = ComboBox2.ListIndex
Combo3Array = Combo2Array
If DelIndex <= Idx Then
For i = DelIndex To Idx - 1
Combo3Array(i) = Combo3Array(i + 1)
Next i
End If
ReDim Preserve Combo3Array(Idx - 1) As Variant
End Sub

Sub ComboBox3_Change()
If ComboBox3.ListIndex < 1 Then DisableCombo4 Else EnableCombo4
End Sub

Sub DisableCombo4()
With ComboBox4
.Clear
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
End With
End Sub

Sub EnableCombo4()
BuildCombo4List
With ComboBox4
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo4Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo4List()
Dim i As Integer
Dim Idx As Integer
Dim DelIndex As Integer
Idx = LastExhibitIdx - 2
ReDim Combo4Array(Idx) As Variant
DelIndex = ComboBox3.ListIndex
Combo4Array = Combo3Array
If DelIndex <= Idx Then
For i = DelIndex To Idx - 1
Combo4Array(i) = Combo4Array(i + 1)
Next i
End If
ReDim Preserve Combo4Array(Idx - 1) As Variant
End Sub

Sub ComboBox4_Change()
If ComboBox4.ListIndex < 1 Then DisableCombo5 Else EnableCombo5
End Sub

Sub DisableCombo5()
With ComboBox5
.Clear
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
End With
End Sub

Sub EnableCombo5()
BuildCombo5List
With ComboBox5
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo5Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo5List()
Dim i As Integer
Dim Idx As Integer
Dim DelIndex As Integer
Idx = LastExhibitIdx - 3
ReDim Combo5Array(Idx) As Variant
DelIndex = ComboBox4.ListIndex
Combo5Array = Combo4Array
If DelIndex <= Idx Then
For i = DelIndex To Idx - 1
Combo5Array(i) = Combo5Array(i + 1)
Next i
End If
ReDim Preserve Combo5Array(Idx - 1) As Variant
End Sub

Sub ComboBox5_Change()
If ComboBox5.ListIndex < 1 Then DisableCombo6 Else EnableCombo6
End Sub

Sub DisableCombo6()
With ComboBox6
.Clear
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
End With
End Sub

Sub EnableCombo6()
BuildCombo6List
With ComboBox6
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo6Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo6List()
Dim i As Integer
Dim Idx As Integer
Dim DelIndex As Integer
Idx = LastExhibitIdx - 4
ReDim Combo6Array(Idx) As Variant
DelIndex = ComboBox5.ListIndex
Combo6Array = Combo5Array
If DelIndex <= Idx Then
For i = DelIndex To Idx - 1
Combo6Array(i) = Combo6Array(i + 1)
Next i
End If
ReDim Preserve Combo6Array(Idx - 1) As Variant
End Sub

Sub ComboBox6_Change()
If ComboBox6.ListIndex < 1 Then DisableCombo7 Else EnableCombo7
End Sub

Sub DisableCombo7()
With ComboBox7
.Clear
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
End With
End Sub

Sub EnableCombo7()
BuildCombo7List
With ComboBox7
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo7Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo7List()
Dim i As Integer
Dim Idx As Integer
Dim DelIndex As Integer
Idx = LastExhibitIdx - 5
ReDim Combo7Array(Idx) As Variant
DelIndex = ComboBox6.ListIndex
Combo7Array = Combo6Array
If DelIndex <= Idx Then
For i = DelIndex To Idx - 1
Combo7Array(i) = Combo7Array(i + 1)
Next i
End If
ReDim Preserve Combo7Array(Idx - 1) As Variant
End Sub

Sub ComboBox7_Change()
If ComboBox7.ListIndex < 1 Then DisableCombo8 Else EnableCombo8
End Sub

Sub DisableCombo8()
With ComboBox8
.Clear
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
End With
End Sub

Sub EnableCombo8()
BuildCombo8List
With ComboBox8
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo8Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo8List()
Dim i As Integer
Dim Idx As Integer
Dim DelIndex As Integer
Idx = LastExhibitIdx - 6
ReDim Combo8Array(Idx) As Variant
DelIndex = ComboBox7.ListIndex
Combo8Array = Combo7Array
If DelIndex <= Idx Then
For i = DelIndex To Idx - 1
Combo8Array(i) = Combo8Array(i + 1)
Next i
End If
ReDim Preserve Combo8Array(Idx - 1) As Variant
End Sub

Sub ComboBox8_Change()
If ComboBox8.ListIndex < 1 Then DisableCombo9 Else EnableCombo9
End Sub

Sub DisableCombo9()
With ComboBox9
.Clear
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
End With
End Sub

Sub EnableCombo9()
BuildCombo9List
With ComboBox9
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo9Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo9List()
Dim i As Integer
Dim Idx As Integer
Dim DelIndex As Integer
Idx = LastExhibitIdx - 7
ReDim Combo9Array(Idx) As Variant
DelIndex = ComboBox8.ListIndex
Combo9Array = Combo8Array
If DelIndex <= Idx Then
For i = DelIndex To Idx - 1
Combo9Array(i) = Combo9Array(i + 1)
Next i
End If
ReDim Preserve Combo9Array(Idx - 1) As Variant
End Sub

Sub ComboBox9_Change()
If ComboBox9.ListIndex < 1 Then DisableCombo10 Else EnableCombo10
End Sub

Sub DisableCombo10()
With ComboBox10
.Clear
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
End With
End Sub

Sub EnableCombo10()
BuildCombo10List
With ComboBox10
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo10Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo10List()
Dim i As Integer
Dim Idx As Integer
Dim DelIndex As Integer
Idx = LastExhibitIdx - 8
ReDim Combo10Array(Idx) As Variant
DelIndex = ComboBox9.ListIndex
Combo10Array = Combo9Array
If DelIndex <= Idx Then
For i = DelIndex To Idx - 1
Combo10Array(i) = Combo10Array(i + 1)
Next i
End If
ReDim Preserve Combo10Array(Idx - 1) As Variant
End Sub

Sub ComboBox10_Change()
If ComboBox10.ListIndex < 1 Then DisableCombo11 Else EnableCombo11
End Sub

Sub DisableCombo11()
With ComboBox11
.Clear
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
End With
End Sub

Sub EnableCombo11()
BuildCombo11List
With ComboBox11
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo11Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo11List()
Dim i As Integer
Dim Idx As Integer
Dim DelIndex As Integer
Idx = LastExhibitIdx - 9
ReDim Combo11Array(Idx) As Variant
DelIndex = ComboBox10.ListIndex
Combo11Array = Combo10Array
If DelIndex <= Idx Then
For i = DelIndex To Idx - 1
Combo11Array(i) = Combo11Array(i + 1)
Next i
End If
ReDim Preserve Combo11Array(Idx - 1) As Variant
End Sub

Sub ComboBox11_Change()
If ComboBox11.ListIndex < 1 Then DisableCombo12 Else EnableCombo12
End Sub

Sub DisableCombo12()
With ComboBox12
.Clear
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
End With
End Sub

Sub EnableCombo12()
BuildCombo12List
With ComboBox12
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo12Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo12List()
Dim i As Integer
Dim Idx As Integer
Dim DelIndex As Integer
Idx = LastExhibitIdx - 10
ReDim Combo12Array(Idx) As Variant
DelIndex = ComboBox11.ListIndex
Combo12Array = Combo11Array
If DelIndex <= Idx Then
For i = DelIndex To Idx - 1
Combo12Array(i) = Combo12Array(i + 1)
Next i
End If
ReDim Preserve Combo12Array(Idx - 1) As Variant
End Sub

Sub ComboBox12_Change()
If ComboBox12.ListIndex < 1 Then DisableCombo13 Else EnableCombo13
End Sub

Sub DisableCombo13()
With ComboBox13
.Clear
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
End With
End Sub

Sub EnableCombo13()
BuildCombo13List
With ComboBox13
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo13Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo13List()
Dim i As Integer
Dim Idx As Integer
Dim DelIndex As Integer
Idx = LastExhibitIdx - 11
ReDim Combo13Array(Idx) As Variant
DelIndex = ComboBox12.ListIndex
Combo13Array = Combo12Array
If DelIndex <= Idx Then
For i = DelIndex To Idx - 1
Combo13Array(i) = Combo13Array(i + 1)
Next i
End If
ReDim Preserve Combo13Array(Idx - 1) As Variant
End Sub

Sub ComboBox13_Change()
If ComboBox13.ListIndex < 1 Then DisableCombo14 Else EnableCombo14
End Sub

Sub DisableCombo14()
With ComboBox14
.Clear
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
End With
End Sub

Sub EnableCombo14()
BuildCombo14List
With ComboBox14
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo14Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo14List()
Dim i As Integer
Dim Idx As Integer
Dim DelIndex As Integer
Idx = LastExhibitIdx - 12
ReDim Combo14Array(Idx) As Variant
DelIndex = ComboBox13.ListIndex
Combo14Array = Combo13Array
If DelIndex <= Idx Then
For i = DelIndex To Idx - 1
Combo14Array(i) = Combo14Array(i + 1)
Next i
End If
ReDim Preserve Combo14Array(Idx - 1) As Variant
End Sub

Sub btnOK_Click()
bNewDoc = True
Me.Hide
End Sub

Sub btnCancel_Click()
Dim myResult As Integer
myResult = MsgBox("Confirm?", vbYesNo, "Cancel")
If myResult = 6 Then
bNewDoc = False
Me.Hide
End If
End Sub

Now back to the main module code, which actually picks up from the line "If
bNewDoc = True Then CollectUserFormValues" and then continues as follows:

Sub CollectUserFormValues()
With myForm
With .ComboBox1
Combo1Val = .Value
Combo1Idx = .ListIndex
End With
With .ComboBox2
Combo2Val = .Value
Combo2Idx = .ListIndex
End With
With .ComboBox3
Combo3Val = .Value
Combo3Idx = .ListIndex
End With
With .ComboBox4
Combo4Val = .Value
Combo4Idx = .ListIndex
End With
With .ComboBox5
Combo5Val = .Value
Combo5Idx = .ListIndex
End With
With .ComboBox6
Combo6Val = .Value
Combo6Idx = .ListIndex
End With
With .ComboBox7
Combo7Val = .Value
Combo7Idx = .ListIndex
End With
With .ComboBox8
Combo8Val = .Value
Combo8Idx = .ListIndex
End With
With .ComboBox9
Combo9Val = .Value
Combo9Idx = .ListIndex
End With
With .ComboBox10
Combo10Val = .Value
Combo10Idx = .ListIndex
End With
With .ComboBox11
Combo11Val = .Value
Combo11Idx = .ListIndex
End With
With .ComboBox12
Combo12Val = .Value
Combo12Idx = .ListIndex
End With
With .ComboBox13
Combo13Val = .Value
Combo13Idx = .ListIndex
End With
With .ComboBox14
Combo14Val = .Value
Combo14Idx = .ListIndex
End With
End With
End Sub

Sub BuildDoc()
InsertBookmarkValue "Exhibit1", Combo1Val
If Combo2Idx > 0 Then
ShowBookmarkRange "NoExhibit2"
InsertBookmarkValue "Exhibit2", Combo2Val
Else: HideBookmarkRange "NoExhibit2"
End If
If Combo3Idx > 0 Then
ShowBookmarkRange "NoExhibit3"
InsertBookmarkValue "Exhibit3", Combo3Val
Else: HideBookmarkRange "NoExhibit3"
End If
If Combo4Idx > 0 Then
ShowBookmarkRange "NoExhibit4"
InsertBookmarkValue "Exhibit4", Combo4Val
Else: HideBookmarkRange "NoExhibit4"
End If
If Combo5Idx > 0 Then
ShowBookmarkRange "NoExhibit5"
InsertBookmarkValue "Exhibit5", Combo5Val
Else: HideBookmarkRange "NoExhibit5"
End If
If Combo6Idx > 0 Then
ShowBookmarkRange "NoExhibit6"
InsertBookmarkValue "Exhibit6", Combo6Val
Else: HideBookmarkRange "NoExhibit6"
End If
If Combo7Idx > 0 Then
ShowBookmarkRange "NoExhibit7"
InsertBookmarkValue "Exhibit7", Combo7Val
Else: HideBookmarkRange "NoExhibit7"
End If
If Combo8Idx > 0 Then
ShowBookmarkRange "NoExhibit8"
InsertBookmarkValue "Exhibit8", Combo8Val
Else: HideBookmarkRange "NoExhibit8"
End If
If Combo9Idx > 0 Then
ShowBookmarkRange "NoExhibit9"
InsertBookmarkValue "Exhibit9", Combo9Val
Else: HideBookmarkRange "NoExhibit9"
End If
If Combo10Idx > 0 Then
ShowBookmarkRange "NoExhibit10"
InsertBookmarkValue "Exhibit10", Combo10Val
Else: HideBookmarkRange "NoExhibit10"
End If
If Combo11Idx > 0 Then
ShowBookmarkRange "NoExhibit11"
InsertBookmarkValue "Exhibit11", Combo11Val
Else: HideBookmarkRange "NoExhibit11"
End If
If Combo12Idx > 0 Then
ShowBookmarkRange "NoExhibit12"
InsertBookmarkValue "Exhibit12", Combo12Val
Else: HideBookmarkRange "NoExhibit12"
End If
If Combo13Idx > 0 Then
ShowBookmarkRange "NoExhibit13"
InsertBookmarkValue "Exhibit13", Combo13Val
Else: HideBookmarkRange "NoExhibit13"
End If
If Combo14Idx > 0 Then
ShowBookmarkRange "NoExhibit14"
InsertBookmarkValue "Exhibit14", Combo14Val
Else: HideBookmarkRange "NoExhibit14"
End If
With ActiveWindow.View
.ShowBookmarks = False
.ShowHiddenText = False
.ShowAll = False
End With
End Sub

Sub InsertBookmarkValue(BkmkName As String, Value As String)
With myDoc
If .Bookmarks.Exists(BkmkName) = True Then
Dim myRange As Range
Set myRange = .Bookmarks(BkmkName).Range
myRange.Text = Value
.Bookmarks.Add BkmkName, myRange
End If
End With
End Sub

Sub ShowBookmarkRange(BkmkName As String)
With myDoc
If .Bookmarks.Exists(BkmkName) = True Then
..Bookmarks(BkmkName).Range.Font.Hidden = False
End With
End Sub

Sub HideBookmarkRange(BkmkName As String)
With myDoc
If .Bookmarks.Exists(BkmkName) = True Then
..Bookmarks(BkmkName).Range.Font.Hidden = True
End With
End Sub

There are a couple of clunky bits in this - given more time I'd probably
develop a function for building the ComboBox lists or at least use the upper
bound of the previous array to dimension the current array - but it should
achieve the desired result. The only real "user-friendliness" risk that I can
see is that if the user gets to the last ComboBox and realises that they're
short or long, they have to start over. Also, there's no validation to ensure
that a value has been selected for every ComboBox - but at least "[SELECT]"
doesn't end up in the document if one is missed.

As promised, I'll email you the template shortly.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
G

Gordon Bentley-Mix

Bit of "validation" code to ensure that the 'OK' button is enabled only if a
value has been selected for every possible ComboBox:

Sub CheckOKStatus()
Dim bLastExhibitOK As Boolean
Dim bCombo1OK As Boolean
Dim bCombo2OK As Boolean
Dim bCombo3OK As Boolean
Dim bCombo4OK As Boolean
Dim bCombo5OK As Boolean
Dim bCombo6OK As Boolean
Dim bCombo7OK As Boolean
Dim bCombo8OK As Boolean
Dim bCombo9OK As Boolean
Dim bCombo10OK As Boolean
Dim bCombo11OK As Boolean
Dim bCombo12OK As Boolean
Dim bCombo13OK As Boolean
Dim bCombo14OK As Boolean
Select Case LastExhibitIdx
Case 1
bLastExhibitOK = True
If ComboBox1.ListIndex > 0 Then bCombo1OK = True Else bCombo1OK =
False
bCombo2OK = True
bCombo3OK = True
bCombo4OK = True
bCombo5OK = True
bCombo6OK = True
bCombo7OK = True
bCombo8OK = True
bCombo9OK = True
bCombo10OK = True
bCombo11OK = True
bCombo12OK = True
bCombo13OK = True
bCombo14OK = True
Case 2
bLastExhibitOK = True
If ComboBox1.ListIndex > 0 Then bCombo1OK = True Else bCombo1OK =
False
If ComboBox2.ListIndex > 0 Then bCombo2OK = True Else bCombo2OK =
False
bCombo3OK = True
bCombo4OK = True
bCombo5OK = True
bCombo6OK = True
bCombo7OK = True
bCombo8OK = True
bCombo9OK = True
bCombo10OK = True
bCombo11OK = True
bCombo12OK = True
bCombo13OK = True
bCombo14OK = True
Case 3
bLastExhibitOK = True
If ComboBox1.ListIndex > 0 Then bCombo1OK = True Else bCombo1OK =
False
If ComboBox2.ListIndex > 0 Then bCombo2OK = True Else bCombo2OK =
False
If ComboBox3.ListIndex > 0 Then bCombo3OK = True Else bCombo3OK =
False
bCombo4OK = True
bCombo5OK = True
bCombo6OK = True
bCombo7OK = True
bCombo8OK = True
bCombo9OK = True
bCombo10OK = True
bCombo11OK = True
bCombo12OK = True
bCombo13OK = True
bCombo14OK = True
Case 4
bLastExhibitOK = True
If ComboBox1.ListIndex > 0 Then bCombo1OK = True Else bCombo1OK =
False
If ComboBox2.ListIndex > 0 Then bCombo2OK = True Else bCombo2OK =
False
If ComboBox3.ListIndex > 0 Then bCombo3OK = True Else bCombo3OK =
False
If ComboBox4.ListIndex > 0 Then bCombo4OK = True Else bCombo4OK =
False
bCombo5OK = True
bCombo6OK = True
bCombo7OK = True
bCombo8OK = True
bCombo9OK = True
bCombo10OK = True
bCombo11OK = True
bCombo12OK = True
bCombo13OK = True
bCombo14OK = True
Case 5
bLastExhibitOK = True
If ComboBox1.ListIndex > 0 Then bCombo1OK = True Else bCombo1OK =
False
If ComboBox2.ListIndex > 0 Then bCombo2OK = True Else bCombo2OK =
False
If ComboBox3.ListIndex > 0 Then bCombo3OK = True Else bCombo3OK =
False
If ComboBox4.ListIndex > 0 Then bCombo4OK = True Else bCombo4OK =
False
If ComboBox5.ListIndex > 0 Then bCombo5OK = True Else bCombo5OK =
False
bCombo6OK = True
bCombo7OK = True
bCombo8OK = True
bCombo9OK = True
bCombo10OK = True
bCombo11OK = True
bCombo12OK = True
bCombo13OK = True
bCombo14OK = True
Case 6
bLastExhibitOK = True
If ComboBox1.ListIndex > 0 Then bCombo1OK = True Else bCombo1OK =
False
If ComboBox2.ListIndex > 0 Then bCombo2OK = True Else bCombo2OK =
False
If ComboBox3.ListIndex > 0 Then bCombo3OK = True Else bCombo3OK =
False
If ComboBox4.ListIndex > 0 Then bCombo4OK = True Else bCombo4OK =
False
If ComboBox5.ListIndex > 0 Then bCombo5OK = True Else bCombo5OK =
False
If ComboBox6.ListIndex > 0 Then bCombo6OK = True Else bCombo6OK =
False
bCombo7OK = True
bCombo8OK = True
bCombo9OK = True
bCombo10OK = True
bCombo11OK = True
bCombo12OK = True
bCombo13OK = True
bCombo14OK = True
Case 7
bLastExhibitOK = True
If ComboBox1.ListIndex > 0 Then bCombo1OK = True Else bCombo1OK =
False
If ComboBox2.ListIndex > 0 Then bCombo2OK = True Else bCombo2OK =
False
If ComboBox3.ListIndex > 0 Then bCombo3OK = True Else bCombo3OK =
False
If ComboBox4.ListIndex > 0 Then bCombo4OK = True Else bCombo4OK =
False
If ComboBox5.ListIndex > 0 Then bCombo5OK = True Else bCombo5OK =
False
If ComboBox6.ListIndex > 0 Then bCombo6OK = True Else bCombo6OK =
False
If ComboBox7.ListIndex > 0 Then bCombo7OK = True Else bCombo7OK =
False
bCombo8OK = True
bCombo9OK = True
bCombo10OK = True
bCombo11OK = True
bCombo12OK = True
bCombo13OK = True
bCombo14OK = True
Case 8
bLastExhibitOK = True
If ComboBox1.ListIndex > 0 Then bCombo1OK = True Else bCombo1OK =
False
If ComboBox2.ListIndex > 0 Then bCombo2OK = True Else bCombo2OK =
False
If ComboBox3.ListIndex > 0 Then bCombo3OK = True Else bCombo3OK =
False
If ComboBox4.ListIndex > 0 Then bCombo4OK = True Else bCombo4OK =
False
If ComboBox5.ListIndex > 0 Then bCombo5OK = True Else bCombo5OK =
False
If ComboBox6.ListIndex > 0 Then bCombo6OK = True Else bCombo6OK =
False
If ComboBox7.ListIndex > 0 Then bCombo7OK = True Else bCombo7OK =
False
If ComboBox8.ListIndex > 0 Then bCombo8OK = True Else bCombo8OK =
False
bCombo9OK = True
bCombo10OK = True
bCombo11OK = True
bCombo12OK = True
bCombo13OK = True
bCombo14OK = True
Case 9
bLastExhibitOK = True
If ComboBox1.ListIndex > 0 Then bCombo1OK = True Else bCombo1OK =
False
If ComboBox2.ListIndex > 0 Then bCombo2OK = True Else bCombo2OK =
False
If ComboBox3.ListIndex > 0 Then bCombo3OK = True Else bCombo3OK =
False
If ComboBox4.ListIndex > 0 Then bCombo4OK = True Else bCombo4OK =
False
If ComboBox5.ListIndex > 0 Then bCombo5OK = True Else bCombo5OK =
False
If ComboBox6.ListIndex > 0 Then bCombo6OK = True Else bCombo6OK =
False
If ComboBox7.ListIndex > 0 Then bCombo7OK = True Else bCombo7OK =
False
If ComboBox8.ListIndex > 0 Then bCombo8OK = True Else bCombo8OK =
False
If ComboBox9.ListIndex > 0 Then bCombo9OK = True Else bCombo9OK =
False
bCombo10OK = True
bCombo11OK = True
bCombo12OK = True
bCombo13OK = True
bCombo14OK = True
Case 10
bLastExhibitOK = True
If ComboBox1.ListIndex > 0 Then bCombo1OK = True Else bCombo1OK =
False
If ComboBox2.ListIndex > 0 Then bCombo2OK = True Else bCombo2OK =
False
If ComboBox3.ListIndex > 0 Then bCombo3OK = True Else bCombo3OK =
False
If ComboBox4.ListIndex > 0 Then bCombo4OK = True Else bCombo4OK =
False
If ComboBox5.ListIndex > 0 Then bCombo5OK = True Else bCombo5OK =
False
If ComboBox6.ListIndex > 0 Then bCombo6OK = True Else bCombo6OK =
False
If ComboBox7.ListIndex > 0 Then bCombo7OK = True Else bCombo7OK =
False
If ComboBox8.ListIndex > 0 Then bCombo8OK = True Else bCombo8OK =
False
If ComboBox9.ListIndex > 0 Then bCombo9OK = True Else bCombo9OK =
False
If ComboBox10.ListIndex > 0 Then bCombo10OK = True Else bCombo10OK =
False
bCombo11OK = True
bCombo12OK = True
bCombo13OK = True
bCombo14OK = True
Case 11
bLastExhibitOK = True
If ComboBox1.ListIndex > 0 Then bCombo1OK = True Else bCombo1OK =
False
If ComboBox2.ListIndex > 0 Then bCombo2OK = True Else bCombo2OK =
False
If ComboBox3.ListIndex > 0 Then bCombo3OK = True Else bCombo3OK =
False
If ComboBox4.ListIndex > 0 Then bCombo4OK = True Else bCombo4OK =
False
If ComboBox5.ListIndex > 0 Then bCombo5OK = True Else bCombo5OK =
False
If ComboBox6.ListIndex > 0 Then bCombo6OK = True Else bCombo6OK =
False
If ComboBox7.ListIndex > 0 Then bCombo7OK = True Else bCombo7OK =
False
If ComboBox8.ListIndex > 0 Then bCombo8OK = True Else bCombo8OK =
False
If ComboBox9.ListIndex > 0 Then bCombo9OK = True Else bCombo9OK =
False
If ComboBox10.ListIndex > 0 Then bCombo10OK = True Else bCombo10OK =
False
If ComboBox11.ListIndex > 0 Then bCombo11OK = True Else bCombo11OK =
False
bCombo12OK = True
bCombo13OK = True
bCombo14OK = True
Case 12
bLastExhibitOK = True
If ComboBox1.ListIndex > 0 Then bCombo1OK = True Else bCombo1OK =
False
If ComboBox2.ListIndex > 0 Then bCombo2OK = True Else bCombo2OK =
False
If ComboBox3.ListIndex > 0 Then bCombo3OK = True Else bCombo3OK =
False
If ComboBox4.ListIndex > 0 Then bCombo4OK = True Else bCombo4OK =
False
If ComboBox5.ListIndex > 0 Then bCombo5OK = True Else bCombo5OK =
False
If ComboBox6.ListIndex > 0 Then bCombo6OK = True Else bCombo6OK =
False
If ComboBox7.ListIndex > 0 Then bCombo7OK = True Else bCombo7OK =
False
If ComboBox8.ListIndex > 0 Then bCombo8OK = True Else bCombo8OK =
False
If ComboBox9.ListIndex > 0 Then bCombo9OK = True Else bCombo9OK =
False
If ComboBox10.ListIndex > 0 Then bCombo10OK = True Else bCombo10OK =
False
If ComboBox11.ListIndex > 0 Then bCombo11OK = True Else bCombo11OK =
False
If ComboBox12.ListIndex > 0 Then bCombo12OK = True Else bCombo12OK =
False
bCombo13OK = True
bCombo14OK = True
Case 13
bLastExhibitOK = True
If ComboBox1.ListIndex > 0 Then bCombo1OK = True Else bCombo1OK =
False
If ComboBox2.ListIndex > 0 Then bCombo2OK = True Else bCombo2OK =
False
If ComboBox3.ListIndex > 0 Then bCombo3OK = True Else bCombo3OK =
False
If ComboBox4.ListIndex > 0 Then bCombo4OK = True Else bCombo4OK =
False
If ComboBox5.ListIndex > 0 Then bCombo5OK = True Else bCombo5OK =
False
If ComboBox6.ListIndex > 0 Then bCombo6OK = True Else bCombo6OK =
False
If ComboBox7.ListIndex > 0 Then bCombo7OK = True Else bCombo7OK =
False
If ComboBox8.ListIndex > 0 Then bCombo8OK = True Else bCombo8OK =
False
If ComboBox9.ListIndex > 0 Then bCombo9OK = True Else bCombo9OK =
False
If ComboBox10.ListIndex > 0 Then bCombo10OK = True Else bCombo10OK =
False
If ComboBox11.ListIndex > 0 Then bCombo11OK = True Else bCombo11OK =
False
If ComboBox12.ListIndex > 0 Then bCombo12OK = True Else bCombo12OK =
False
If ComboBox13.ListIndex > 0 Then bCombo13OK = True Else bCombo13OK =
False
bCombo14OK = True
Case 14
bLastExhibitOK = True
If ComboBox1.ListIndex > 0 Then bCombo1OK = True Else bCombo1OK =
False
If ComboBox2.ListIndex > 0 Then bCombo2OK = True Else bCombo2OK =
False
If ComboBox3.ListIndex > 0 Then bCombo3OK = True Else bCombo3OK =
False
If ComboBox4.ListIndex > 0 Then bCombo4OK = True Else bCombo4OK =
False
If ComboBox5.ListIndex > 0 Then bCombo5OK = True Else bCombo5OK =
False
If ComboBox6.ListIndex > 0 Then bCombo6OK = True Else bCombo6OK =
False
If ComboBox7.ListIndex > 0 Then bCombo7OK = True Else bCombo7OK =
False
If ComboBox8.ListIndex > 0 Then bCombo8OK = True Else bCombo8OK =
False
If ComboBox9.ListIndex > 0 Then bCombo9OK = True Else bCombo9OK =
False
If ComboBox10.ListIndex > 0 Then bCombo10OK = True Else bCombo10OK =
False
If ComboBox11.ListIndex > 0 Then bCombo11OK = True Else bCombo11OK =
False
If ComboBox12.ListIndex > 0 Then bCombo12OK = True Else bCombo12OK =
False
If ComboBox13.ListIndex > 0 Then bCombo13OK = True Else bCombo13OK =
False
If ComboBox14.ListIndex > 0 Then bCombo14OK = True Else bCombo14OK =
False
Case Else
bLastExhibitOK = False
bCombo1OK = False
bCombo2OK = False
bCombo3OK = False
bCombo4OK = False
bCombo5OK = False
bCombo6OK = False
bCombo7OK = False
bCombo8OK = False
bCombo9OK = False
bCombo10OK = False
bCombo11OK = False
bCombo12OK = False
bCombo13OK = False
bCombo14OK = False
End Select
If bLastExhibitOK = True And bCombo2OK = True And bCombo1OK = True _
And bCombo3OK = True And bCombo4OK = True And bCombo5OK = True _
And bCombo6OK = True And bCombo7OK = True And bCombo8OK = True _
And bCombo9OK = True And bCombo10OK = True And bCombo11OK = True _
And bCombo12OK = True And bCombo13OK = True And bCombo14OK = True Then
EnableOKButton
Else: DisableOKButton
End If
End Sub

Sub EnableOKButton()
btnCancel.Default = False
With btnOK
.Enabled = True
.Locked = False
.TabStop = True
.Default = True
End With
End Sub

Sub DisableOKButton()
With btnOK
.Enabled = False
.Locked = True
.TabStop = False
.Default = False
End With
btnCancel.Default = False
End Sub

Just make a call to the CheckOKStatus procedure on the Change event for
every ComboBox.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
J

Jules

I'd appreciate the template (but so far my form is working well) - I'll add
today's code in now.
Glad you needed to do this Gordon - thank you.
 
G

Gordon Bentley-Mix

On its way! (I really should start charging for this stuff...)
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
R

Rand8203

This was what I needed. Thanks so much for your assistance. It is greatly
appreciated.

Gordon Bentley-Mix said:
The Full Monty -

Still assuming the same as in my first post - just more: ComboBoxes number 1
through 14 plus a ComboBox (with a Label) for selecting the "last exhibit";
an 'OK' and 'Cancel' button; bookmarks for each ComboBox called "Exhibit1"
through "Exhibit14" and the related "NoExhibit" bookmarks (1 - 14).

Another case of "more of the same" code in the main module, as follows:

Option Explicit

Public bNewDoc As Boolean
Public myDoc As Document
Public myForm As UserForm1
Dim Combo1Val As String
Dim Combo1Idx As Integer
Dim Combo2Val As String
Dim Combo2Idx As Integer
Dim Combo3Val As String
Dim Combo3Idx As Integer
Dim Combo4Val As String
Dim Combo4Idx As Integer
Dim Combo5Val As String
Dim Combo5Idx As Integer
Dim Combo6Val As String
Dim Combo6Idx As Integer
Dim Combo7Val As String
Dim Combo7Idx As Integer
Dim Combo8Val As String
Dim Combo8Idx As Integer
Dim Combo9Val As String
Dim Combo9Idx As Integer
Dim Combo10Val As String
Dim Combo10Idx As Integer
Dim Combo11Val As String
Dim Combo11Idx As Integer
Dim Combo12Val As String
Dim Combo12Idx As Integer
Dim Combo13Val As String
Dim Combo13Idx As Integer
Dim Combo14Val As String
Dim Combo14Idx As Integer

Sub AutoNew()
Set myDoc = ActiveDocument
Set myForm = New UserForm1
Load myForm
myForm.Show
If bNewDoc = True Then CollectUserFormValues
Unload myForm
Set myForm = Nothing
If bNewDoc = True Then BuildDoc Else myDoc.Close wdDoNotSaveChanges
End Sub

And again, control is handed over the the UserForm code when the UserForm is
shown. Lots more code in this module, however, and it will probably require
some explanation.

Option Explicit

Dim LastExhibitIdx As Integer '*** Used to keep track of the "last exhibit"
Dim Combo1Array() As Variant
Dim Combo2Array() As Variant
Dim Combo3Array() As Variant
Dim Combo4Array() As Variant
Dim Combo5Array() As Variant
Dim Combo6Array() As Variant
Dim Combo7Array() As Variant
Dim Combo8Array() As Variant
Dim Combo9Array() As Variant
Dim Combo10Array() As Variant
Dim Combo11Array() As Variant
Dim Combo12Array() As Variant
Dim Combo13Array() As Variant
Dim Combo14Array() As Variant
Dim Combo15Array() As Variant

Sub UserForm_Initialize()
LoadLastExhibitCombo
InitializeCombos
End Sub

Sub LoadLastExhibitCombo()
'***Loads values of "A" to "N" into the ComboBox for the "last exhibit"
Dim myArray As Variant
myArray = Split("[SELECT]|A|B|C|D|E|F|G|H|I|J|K|L|M|N", "|")
With cboLastExhibit
.List = myArray
.ListIndex = 0
End With
End Sub

Sub InitializeCombos()
'***Disables all of the other ComboBoxes - could do this manually but since
there's
' code that does it...
DisableCombo1
DisableCombo2
DisableCombo3
DisableCombo4
DisableCombo5
DisableCombo6
DisableCombo7
DisableCombo8
DisableCombo9
DisableCombo10
DisableCombo11
DisableCombo12
DisableCombo13
DisableCombo14
End Sub

Sub cboLastExhibit_Change()
LastExhibitIdx = cboLastExhibit.ListIndex
ShowExhibitCombos (LastExhibitIdx)
End Sub

Private Sub ShowExhibitCombos(NumberToShow As Integer)
'***Hides/shows the correct number of ComboBoxes depending on the value
' selected for the "last exhibit" ComboBox
ComboBox1.Visible = False
ComboBox2.Visible = False
ComboBox3.Visible = False
ComboBox4.Visible = False
ComboBox5.Visible = False
ComboBox6.Visible = False
ComboBox7.Visible = False
ComboBox8.Visible = False
ComboBox9.Visible = False
ComboBox10.Visible = False
ComboBox11.Visible = False
ComboBox12.Visible = False
ComboBox13.Visible = False
ComboBox14.Visible = False
If NumberToShow > 0 Then
ComboBox1.Visible = True
EnableCombo1
If NumberToShow > 1 Then
ComboBox2.Visible = True
If NumberToShow > 2 Then
ComboBox3.Visible = True
If NumberToShow > 3 Then
ComboBox4.Visible = True
If NumberToShow > 4 Then
ComboBox5.Visible = True
If NumberToShow > 5 Then
ComboBox6.Visible = True
If NumberToShow > 6 Then
ComboBox7.Visible = True
If NumberToShow > 7 Then
ComboBox8.Visible = True
If NumberToShow > 8 Then
ComboBox9.Visible = True
If NumberToShow > 9 Then
ComboBox10.Visible = True
If NumberToShow > 10 Then
ComboBox11.Visible = True
If NumberToShow > 11 Then
ComboBox12.Visible = True
If NumberToShow > 12 Then
ComboBox13.Visible =
True
If NumberToShow > 13
Then

ComboBox14.Visible = True
Else

ComboBox14.Visible = False
End If
Else
ComboBox13.Visible =
False
End If
Else
ComboBox12.Visible = False
End If
Else
ComboBox11.Visible = False
End If
Else
ComboBox10.Visible = False
End If
Else
ComboBox9.Visible = False
End If
Else
ComboBox8.Visible = False
End If
Else
ComboBox7.Visible = False
End If
Else
ComboBox6.Visible = False
End If
Else
ComboBox5.Visible = False
End If
Else
ComboBox4.Visible = False
End If
Else
ComboBox3.Visible = False
End If
Else
ComboBox2.Visible = False
End If
Else
ComboBox1.Visible = False
End If
End Sub

'***Enable, Disable and BuildList procedures for each ComboBox similar to
' previous - just more of 'em; also BuildLists based off the "last
exhibit" value
Sub DisableCombo1()
With ComboBox1
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
.Clear
End With
End Sub

Sub EnableCombo1()
BuildCombo1List
With ComboBox1
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo1Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo1List()
Dim i As Integer
Dim Idx As Integer
Dim ExhibitName As String
Idx = LastExhibitIdx
ReDim Combo1Array(LastExhibitIdx) As Variant
Combo1Array(0) = "[SELECT]"
For i = 1 To Idx
ExhibitName = "Exhibit " & cboLastExhibit.List(i)
Combo1Array(i) = ExhibitName
Next i
With ComboBox1
.List = Combo1Array
.ListIndex = 0
End With
End Sub

Sub ComboBox1_Change()
If ComboBox1.ListIndex < 1 Then DisableCombo2 Else EnableCombo2
End Sub

Sub DisableCombo2()
With ComboBox2
.Clear
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
End With
End Sub

Sub EnableCombo2()
BuildCombo2List
With ComboBox2
.Clear
.Enabled = True
.Locked = False
.TabStop = True
.BackColor = &H80000005
.List = Combo2Array
.ListIndex = 0
End With
End Sub

Sub BuildCombo2List()
Dim i As Integer
Dim Idx As Integer
Dim DelIndex As Integer
Idx = LastExhibitIdx
ReDim Combo2Array(Idx) As Variant
DelIndex = ComboBox1.ListIndex
Combo2Array = Combo1Array
If DelIndex <= Idx Then
For i = DelIndex To Idx - 1
Combo2Array(i) = Combo2Array(i + 1)
Next i
End If
ReDim Preserve Combo2Array(Idx - 1) As Variant
End Sub

Sub ComboBox2_Change()
If ComboBox2.ListIndex < 1 Then DisableCombo3 Else EnableCombo3
 
D

Dave Shehane in Oregon

I have been having trouble getting this example to run - I am a real novice
at VBA and trying to learn by example! And this looks like it demonstrates a
bunch of things I want to learn, but I am a bit lost. Any chance that you
could post or send a working template? Life would be so much easier!

Thanks,
 
G

Gordon Bentley-Mix

Dave,

Only because we were once almost neighbours (I grew up in Richland, WA)...

Email me at the address in my profile and I'll send you a copy.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 

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