PKisielewski
03-28-2008, 09:40 AM
I have a form that has a ActiveX combo box which is populated by the Document Open sub:
cbo_DocBase1.AddItem "Select DocBase"
cbo_DocBase1.AddItem "Item 1"
cbo_DocBase1.AddItem "Item 2
Below the combo box I have inserted a bookmark (docbase)
When the user selects from the dropdown selection an onchange event goes to the docbase bookmark location - Inserts bookmark titled begin, inserts checkboxes with corresponding text and inserts a bookmark titled end. I would like for these 2 bookmarks (begin and end), the checkboxes and corresponding text to become a range so that if the user selects anything else in the combo box they will be deleted - kind of like a reset. For example, If the user selects Item 2 (I have not included any code for that) after they already select 1 - the items will be deleted and bookmarks begin, end, the new checkboxes will be populated. The code belows includes - if the user selects "Specify DocBase" selection and I need to add the code for Item 2 which I have not completed as of yet.
Code for on change event is as follows:
If cbo_DocBase1.Text = "Item1" Then
Selection.GoTo What:=wdGoToBookmark, Name:="docclass"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
Selection.TypeText Text:=" "
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="begin"
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormCheckBox
Selection.TypeText Text:=" Master Batch Record Documents"
Selection.TypeParagraph
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormCheckBox
Selection.TypeText Text:=" Validation Documents"
Selection.TypeText Text:=" "
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="end"
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
End If
If cbo_DocBase1.Text = "Specify DocBase" Then
Selection.GoTo What:=wdGoToBookmark, Name:="docclass"
Dim aRange
Set aRange = ActiveDocument.Range( _
Start:=ActiveDocument.Bookmarks("begin").Range.Start, _
End:=ActiveDocument.Bookmarks("end").Range.End)
aRange.Range.Delete
End If
End Sub
The text in Red does not work - but it seems logical and maybe I am missing something.
Hopefully I have explained my situation.
Thanks in advance for your help.
edit Lucas: When posting code please select the code and hit the vba button so it will be formatted correctly.
cbo_DocBase1.AddItem "Select DocBase"
cbo_DocBase1.AddItem "Item 1"
cbo_DocBase1.AddItem "Item 2
Below the combo box I have inserted a bookmark (docbase)
When the user selects from the dropdown selection an onchange event goes to the docbase bookmark location - Inserts bookmark titled begin, inserts checkboxes with corresponding text and inserts a bookmark titled end. I would like for these 2 bookmarks (begin and end), the checkboxes and corresponding text to become a range so that if the user selects anything else in the combo box they will be deleted - kind of like a reset. For example, If the user selects Item 2 (I have not included any code for that) after they already select 1 - the items will be deleted and bookmarks begin, end, the new checkboxes will be populated. The code belows includes - if the user selects "Specify DocBase" selection and I need to add the code for Item 2 which I have not completed as of yet.
Code for on change event is as follows:
If cbo_DocBase1.Text = "Item1" Then
Selection.GoTo What:=wdGoToBookmark, Name:="docclass"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
Selection.TypeText Text:=" "
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="begin"
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormCheckBox
Selection.TypeText Text:=" Master Batch Record Documents"
Selection.TypeParagraph
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormCheckBox
Selection.TypeText Text:=" Validation Documents"
Selection.TypeText Text:=" "
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="end"
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
End If
If cbo_DocBase1.Text = "Specify DocBase" Then
Selection.GoTo What:=wdGoToBookmark, Name:="docclass"
Dim aRange
Set aRange = ActiveDocument.Range( _
Start:=ActiveDocument.Bookmarks("begin").Range.Start, _
End:=ActiveDocument.Bookmarks("end").Range.End)
aRange.Range.Delete
End If
End Sub
The text in Red does not work - but it seems logical and maybe I am missing something.
Hopefully I have explained my situation.
Thanks in advance for your help.
edit Lucas: When posting code please select the code and hit the vba button so it will be formatted correctly.