C
Cissy
Hi, I'm using Word XP. I must be missing something, but the following code
doesn't work - the combo box won't populate. Thanks for any help.
Option Explicit
Private Sub Document_New()
Dim ofrmLetterhead As frmLetterhead
Dim myRange As Range
Dim combobox1 As ComboBox
Set ofrmLetterhead = New frmLetterhead
With ofrmLetterhead
.txtRecName = ""
.txtRecFirm = ""
.txtAdd1 = ""
.txtAdd2 = ""
.txtCityStateZip = ""
.txtRecName.SetFocus
End With
ofrmLetterhead.Show
If btnOKclicked = True Then
If ofrmLetterhead.optCertified = True Then
ActiveDocument.Bookmarks("bkdelivery").Range.Text = "VIA CERTIFIED MAIL"
End If
If ofrmLetterhead.optFacUS = True Then
ActiveDocument.Bookmarks("bkdelivery").Range.Text = "VIA FACSIMILE AND
U.S. MAIL"
End If
ActiveDocument.Bookmarks("bkRe").Range.Text = ofrmLetterhead.txtRe
ActiveDocument.Bookmarks("bkCC").Range.Text = ofrmLetterhead.txtCC
ActiveDocument.Bookmarks("bkSalutation").Range.Text =
ofrmLetterhead.txtSalutation
ActiveDocument.Bookmarks("bkRecName2").Range.Text =
ofrmLetterhead.txtRecName
If ofrmLetterhead.txtAdd1.Text = "" Then
With ActiveDocument.Bookmarks("bkAdd1")
.Range.Paragraphs(1).Range.Delete
.Delete ' remove the bookmark itself, too
End With
Else
ActiveDocument.Bookmarks("bkAdd1").Range.Text =
ofrmLetterhead.txtAdd1.Text
End If
Set myRange = ActiveDocument.Bookmarks("bkSenderName").Range
myRange.Text = frmLetterhead.combobox1.Value
'Use drop-down list
ofrmLetterhead.combobox1.Style = fmStyleDropDownList
'Combo box values are ListIndex values
ofrmLetterhead.combobox1.BoundColumn = 0
'Set combo box to first entry
ofrmLetterhead.combobox1.ListIndex = 0
With ofrmLetterhead
.combobox1.AddItem "Joe Barber" 'list index 0
.combobox1.AddItem "Sue Turner Budd" ' list index 1
.combobox1.AddItem "Alice Cohen"
.combobox1.AddItem "Tom Chase"
.combobox1.AddItem "Julie Detrick"
End With
Selection.GoTo What:=wdGoToBookmark, Name:="bkStart"
Else
ActiveDocument.Close wdDoNotSaveChanges
End If
Unload ofrmLetterhead
Set ofrmLetterhead = Nothing
End Sub
Private Sub Paste()
'
'
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToBookmark, Name:="bkRecName"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.PasteAndFormat (wdPasteDefault)
'Selection.TypeBackspace
'Selection.Delete Unit:=wdCharacter, Count:=1
End Sub
doesn't work - the combo box won't populate. Thanks for any help.
Option Explicit
Private Sub Document_New()
Dim ofrmLetterhead As frmLetterhead
Dim myRange As Range
Dim combobox1 As ComboBox
Set ofrmLetterhead = New frmLetterhead
With ofrmLetterhead
.txtRecName = ""
.txtRecFirm = ""
.txtAdd1 = ""
.txtAdd2 = ""
.txtCityStateZip = ""
.txtRecName.SetFocus
End With
ofrmLetterhead.Show
If btnOKclicked = True Then
If ofrmLetterhead.optCertified = True Then
ActiveDocument.Bookmarks("bkdelivery").Range.Text = "VIA CERTIFIED MAIL"
End If
If ofrmLetterhead.optFacUS = True Then
ActiveDocument.Bookmarks("bkdelivery").Range.Text = "VIA FACSIMILE AND
U.S. MAIL"
End If
ActiveDocument.Bookmarks("bkRe").Range.Text = ofrmLetterhead.txtRe
ActiveDocument.Bookmarks("bkCC").Range.Text = ofrmLetterhead.txtCC
ActiveDocument.Bookmarks("bkSalutation").Range.Text =
ofrmLetterhead.txtSalutation
ActiveDocument.Bookmarks("bkRecName2").Range.Text =
ofrmLetterhead.txtRecName
If ofrmLetterhead.txtAdd1.Text = "" Then
With ActiveDocument.Bookmarks("bkAdd1")
.Range.Paragraphs(1).Range.Delete
.Delete ' remove the bookmark itself, too
End With
Else
ActiveDocument.Bookmarks("bkAdd1").Range.Text =
ofrmLetterhead.txtAdd1.Text
End If
Set myRange = ActiveDocument.Bookmarks("bkSenderName").Range
myRange.Text = frmLetterhead.combobox1.Value
'Use drop-down list
ofrmLetterhead.combobox1.Style = fmStyleDropDownList
'Combo box values are ListIndex values
ofrmLetterhead.combobox1.BoundColumn = 0
'Set combo box to first entry
ofrmLetterhead.combobox1.ListIndex = 0
With ofrmLetterhead
.combobox1.AddItem "Joe Barber" 'list index 0
.combobox1.AddItem "Sue Turner Budd" ' list index 1
.combobox1.AddItem "Alice Cohen"
.combobox1.AddItem "Tom Chase"
.combobox1.AddItem "Julie Detrick"
End With
Selection.GoTo What:=wdGoToBookmark, Name:="bkStart"
Else
ActiveDocument.Close wdDoNotSaveChanges
End If
Unload ofrmLetterhead
Set ofrmLetterhead = Nothing
End Sub
Private Sub Paste()
'
'
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToBookmark, Name:="bkRecName"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.PasteAndFormat (wdPasteDefault)
'Selection.TypeBackspace
'Selection.Delete Unit:=wdCharacter, Count:=1
End Sub