#1   Report Post  
Posted to microsoft.public.word.docmanagement
Kenny Kenny is offline
external usenet poster
 
Posts: 23
Default ComboBox Help

I am having some problems with my code. I want to select a choice in my
combobox, enter info into two text box's, then update the bookmarks in a
document when the command button is clicked. The text box's are working.
However I cannot get the Case "Army" to work. Please review my code and help
thanks!


Private Sub CommandButton1_Click()
Select Case ComboBox1
Case "Army"
Bookmarks("Address").Range
InsertBefore "Army Base"
End Select
With ActiveDocument
.Bookmarks("Text1").Range _
.InsertBefore TextBox1
.Bookmarks("Text2").Range _
.InsertBefore TextBox2
End With
UserForm1.Hide
End Sub

Private Sub UserForm_Initialize()
ComboBox1.AddItem "Army"
ComboBox1.AddItem "Navy"
ComboBox1.AddItem "Air Force"
ComboBox1.AddItem "Marines"
ComboBox1.Style = fmStyleDropDownList
ComboBox1.BoundColumn = 0
ComboBox1.ListIndex = 0
End Sub



  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 285
Default ComboBox Help

Kenny,

A couple of problems:
Bookmarks("Address").Range
InsertBefore "Army Base"

You are missing the line continuation separator "_"

What bookmarks? It needs to be "ActiveDocument.Bookmarks"

Also your "Case" statement will never be true. Try adding:
MsgBox ComboBox1 before your case statement and select Army? It will return
"0" or the listIndex of the item selected. You could use the index and
change the to:
Case Is = 0 and it would work.

Try:
Private Sub CommandButton1_Click()
Dim oRng As Word.Range
Dim oBMs As Bookmarks
Set oBMs = ActiveDocument.Bookmarks
MsgBox ComboBox1
Select Case ComboBox1.Text
Case "Army"
Set oRng = oBMs("Address").Range
oRng.Text = "Army Base"
oBMs.Add "Address", oRng
End Select
With ActiveDocument
Set oRng = oBMs("Text1").Range
oRng.Text = Me.TextBox1.Text
oBMs.Add "Text1", oRng
Set oRng = oBMs("Text2").Range
oRng.Text = Me.TextBox2.Text
oBMs.Add "Text2", oRng
End With
UserForm1.Hide
End Sub
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "Army"
.AddItem "Navy"
.AddItem "Air Force"
.AddItem "Marines"
.Style = fmStyleDropDownList
.BoundColumn = 0
.ListIndex = 0
End With
End Sub






--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Kenny wrote:
I am having some problems with my code. I want to select a choice in
my combobox, enter info into two text box's, then update the
bookmarks in a document when the command button is clicked. The text
box's are working. However I cannot get the Case "Army" to work.
Please review my code and help thanks!


Private Sub CommandButton1_Click()
Select Case ComboBox1
Case "Army"
Bookmarks("Address").Range
InsertBefore "Army Base"
End Select
With ActiveDocument
.Bookmarks("Text1").Range _
.InsertBefore TextBox1
.Bookmarks("Text2").Range _
.InsertBefore TextBox2
End With
UserForm1.Hide
End Sub

Private Sub UserForm_Initialize()
ComboBox1.AddItem "Army"
ComboBox1.AddItem "Navy"
ComboBox1.AddItem "Air Force"
ComboBox1.AddItem "Marines"
ComboBox1.Style = fmStyleDropDownList
ComboBox1.BoundColumn = 0
ComboBox1.ListIndex = 0
End Sub



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dropdown for Combobox jdyon Microsoft Word Help 9 August 11th 06 08:22 PM
ComboBox and UserForm_Initialize Scott Microsoft Word Help 5 April 29th 06 06:08 PM
Combobox, listbox, something! Kim K Microsoft Word Help 1 March 2nd 06 10:33 AM
combobox Gman1959 Microsoft Word Help 1 January 27th 05 11:16 PM
combobox in word Vineet Gupta, MD Microsoft Word Help 2 December 17th 04 12:55 AM


All times are GMT +1. The time now is 01:41 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"