Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box Showing Index Number not Value 2

Status
Not open for further replies.

PackRat1

Technical User
Mar 22, 2006
50
US
I have created 3 Combo Boxes populated with AddItem. The initial template works great. Each drop down allows the user to select the required input. Problem is once you save the document and reopen it all you get is the index number of the selected input. I would use the form dropdown but I'm well over the 25 limit.
Code:
Private Sub ComboBox2_change()

ComboBox2.AddItem "ALL"
ComboBox2.AddItem "ANGUILLA"
ComboBox2.AddItem "ANTIGUA AND BARBUDA"
ComboBox2.AddItem "ARUBA"
ComboBox2.AddItem "BAHAMAS"
ComboBox2.AddItem "BARBADOS"
ComboBox2.AddItem "BELIZE"
....
End Sub

The only thing I removed from above was about 30 AddItems.
 
You populate your ComboBox2 in ComboBox2_Change event, which means you have to type something in it to fire change event.

Consider populating your ComboBox2 in another place, like Form_Load.

Have fun.

---- Andy
 



What APPLICATION?

Why are you hard coding the AddItem Items? It would be much easier and more flexible to have these items in a table.

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Yes, what application? Is this combobox on a userform, or in a document?

BTW: would not ANY change keep adding these? Over and over again, accumulatively? Yup.

Do you have other code you are not telling us about? Something that clear the control, THEN populates it?

Gerry
My paintings and sculpture
 
Ok Sorry for the lack of knowledge, this is my first code in Word. It is in a template (.dot) and all's I'm trying to do is create a drop down list that the user can select from that is about 60 Items long. The selections work with the code the way it is (which I know is incorrect but I was trying to figure this out from past posts and the help files) But once you save the document created from the template and reopen it you only get the index numbers and not the actual selected data. And no there really isn't any other code. I created the comboBox and opened the VB viewer and and inserted the AddItems. I Really appreciate your guys help.
 
I have also tried to define the list as an array but it is so long that the line wraps and sees the new line as new code. So that isn't working either.
 




These all look like Caribbean destinations. You might consider dividing them into other logical groupings and using two combo boxes.

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Unfortunatly The label on the drop down is Country. And the person I am trying to do this for company is located in alot of countries. I am trying to make this form match a SRM form thay will not be rolling out to the entire populace for a while but they want them to be familure with the prompts, hence this form. Most of the form is fields and radio buttons simple until I hit these xlg dropdowns.
 



Tables, mate! It's the way to go rather than data embedded in code.

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
1. Array

Code:
Sub Document_New()
Dim Countries()
Dim var
Countries = Array("ALL", "ANGUILLA", _
     "ANTIGUA AND BARBUDA", "ARUBA", _
     "BAHAMAS", "BARBADOS", "BELIZE")
' for as long as you like

For var = 0 To Ubound(Countries)
  Combobox2.AddItem Countries(var)
Next

End Sub

2. Combobox2 - it is much better to explicitly name things. Combobox2 is not a good name.

3. Again, WHY are you doing this with _Change? It will keep populating the control.

4. Skip is of course correct. Hard coding data is generally not the best way to do this.

5. I used Document_New as you state it is a template. The control will be populated when a new cloned document is created from the template.

6. "The selections work with the code the way it is". You are going to have to explain what that means. I see nothing regarding selection...so what does "the selections" means?

7. "I created the comboBox and opened the VB viewer and and inserted the AddItems." Inserted them how? Not with that _Change procedure.

I can not duplicate the problem - as least as far as you have described it.

I make an ActiveX combobox, populate it with code, save the file as a .DOT, use File>New to clone a new document, select an item, save the file, close it, open it....the selected item is in the combobox.

Gerry
My paintings and sculpture
 
Thanks for the feed back Guys. Gerry I have entered the code as follows:
Code:
Option Explicit

Private Sub ComboBox1_Change()

End Sub

Private Sub ComboBox3_Change()

End Sub

Sub Document_New()
Dim Acompanies()
Dim Asites
Dim Icomp
Dim Isite

Acompanies = Array("ADVANCED STERILIZATION PRODUCTS", "ALZA", "ANIMAS CORPORATION", "BIOSENSE WEBSTER", _
"CENTOCOR", "CLINICAL DIAGNOSTICS SYSTEMS", "CONSUMER PRODUCTS", "CORDIS", "DEPUY", _
"ETHICON", "ETHICON ENDO-SURGERY", "FORT LAUDERDALE", "GLOBAL PHARMACEUTICAL COMMUNICATIONS", _
"HEALTH CARE SYSTEMS", "HEMISFERICA", "IBM", "INDEPENDENCE TECHNOLOGIES", _
"INVERNESS MED TECH", "IOLAB", "J&J CARIBBEAN", "J&J CORPORATE", "J&J INTERVENTIONAL", _
"J&J MEDICAL", "J&J MERCK", "LIFESCAN", "LIFESCAN", " INC.", "MCNEIL CONSUMER AND SPECIALTY PHARMACEUTICALS", _
"MCNEIL CONSUMER HEALTHCARE", "MCNEIL NUTRITIONALS", "NETWORKING & COMPUTING SERVICES", _
"NEUTROGENA", "NEUTROGENA CORP.", "NORAMCO", "ORTHO BIOLOGICS", " INC.", "ORTHO BIOTECH PRODUCTS", _
"ORTHO CLINICAL DIAGNOSTICS", "ORTHO MCNEIL PHARMACEUTICAL", "ORTHO NEUTROGENA", _
"PENINSULA PHARMACEUTICALS", "PHARMACEUTICAL GROUP STRATEGIC MARKETING", "PHARMACEUTICAL RESEARCH & DEVELOPMENT", _
"PPC", "PSGA", "SALES & LOGISTICS COMPANY", "SCIOS", "SHAM TEST", "SPECTACLE LENS GROUP", _
"SUNGARD AVAILABILITY SERVICES", "THERAKOS", "THERAKOS", " INC.", "TIBOTEC THERAPEUTICS", _
"TIBOTEC-VIRCO", "TRANSFORM PHARMACEUTICALS", "VISTAKON")

Asites = Array("ALBANY", "BANGKOK", "BEERSE", "BEIJING", "BOULDER", "BRIDGEWATER", "BROADWAY", _
"BURNABY", "CABO ROJO", "CAGUAS", "CINCINNATI", "EAST TAMAKI", "ELKRIDGE", "EMEA ALL-ECP-BAS", _
"EMEA ALL-EMPLOYEE PRODUCTIVITY", "EMEA ALL-LAN", "EMEA ALL-NETWORKING", "GUANGZHOU", "GURABO", _
"INTERNATIONAL BUSINESS PARK", "ISSY LES MOULINEAUX (PARIS)", "KOWLOON", "LASPIEDRAS", "MIAMI", _
"MINHANG", "MUMBAI", "N/A", "NEW YORK", "NEWBRUNSWICK", "NEWMARKET", "NORTH RYDE", "NORWOOD", _
"NOTTING HILL", "OTHER", "PISCATAWAY", "QUELPH", "RARITAN", "REMOTE USER", "SANGERMAN", "SEOUL", _
"SHANGHAI", "SHINAGAWA", "SINGAPORE", "SKILLMAN", "SOMERVILLE", "SPRINGHOUSE", "SÃO JOSÉ DOS CAMPOS", _
"TAIPEI", "TOKYO", "TOKYO OPERATION CENTER", "TORONTO", "WESTBURY", "XIAN", "YOKOHAMA")

' for as long as you like

For Icomp = 0 To UBound(Acompanies)
  ComboBox1.AddItem Acompanies(Icomp)
  
Next
  
For Isite = 0 To UBound(Asites)
  ComboBox3.AddItem Asites(Isite)
  
Next

End Sub
and I still get numbers in the two combo boxes once I save the document and reopen it.

2.I did not rename the combo boxes due to the fact that there are only two.

3. I am doing this with _Change due to the fact that is what the system creates in the VB code when I insert a combo box in the template.

4. A skip suggested I created two table instead of the arrays above but I was unsucessful in linking them correctly (I am about as green as they come)

6 when I had all of the AddIems as in my first post, when I opened a document with the template all of the selections were there, but I would get numbers once I save the document and reopened it.
7 No I just typed in the data in between the Private Sub and the End Sub.

I have written the code as above saved the document as a .DOT go to file new and open a new document with a template on my computer and select this one. Enter data in some of the fields as well as the combo boxes, save the document and reopen it. The two combo boxes then only contain the index numbers of the data I selected. I am teaching myself VB from posts as well as anything else I can get my hands on. I bought a VB book but it does not seem to cover much on Word or Excel VB programming.

Thanks again for all your guys help.
 
I am not sure to fix these extra wide posts. Very annoying.

Anyway.

1. If you only have TWO comboboxes...why is one named Combobox3.

2. I used your code, exactly as it is - except changing Combobox3 to Combobox2 - as I put in just two comboboxes.

Saved it as a DOT file.

Cloned a new document from the template,

Selected items from each of the comboboxes.

Saved the cloned document.

Closed it.

Opened it.

The selected items are there. No numbers.

So, I can not duplicate this. The comboboxes work they way they are supposed to. Now, you mention other fields. Umm. Tell me about them.

Gerry
My paintings and sculpture
 
Sorry for the wide post I just pasted the code straight from the VB window. So you could see everything.

The form consists mostly of Text form Fields from the forms toolbar menu and Option buttons from the control toolbar grouped into groups to act as radio buttons. (ie yes O no O). There are a couple of drop down form fields from the Forms Toolbar.

The ComboBoxes go from 1 to 3 Because I replaced 2 with a dropdown form field (It contained less than 25 items) and I never bothered to renumber 3.

FOUND IT!!!! IN the properties window the two combo boxes the boundcolumn was bound to 0, I changed it to column 1 and it now retains the correct information.

Thanks!!!
 
Because as I have stated previously. I do not know what I am doing. This is the first VB code I have ever done in word. I was trying any and everything to get this to work.

I tried to change things back if I changed them but I must have missed that one.

Everyone has to start somewhere.

Immense Kudos, Thanks Again.
 
You are absolutely correct. We all started somewhere...in ignorance. I am not being critical. I was simply wondering why you changed it. Normally people do not change parameters willy-nilly (randomly). Um, it is not really a recommended procedure.

I was simply curious why you would change BoundColumns from 1 to 0, when you do not know what it is, or what it is doing.

Gerry
My paintings and sculpture
 
I do not know what I am doing
Then feel free to abuse the F1 key.
 
Gerry the path was:
1 60 AddItems (Between the comboBox_Change())
2 Tried to define an array
3 created tables
4 went back to array (This is when you stepped in)
I knew what the boundcolumn did and was trying to get it to select the correct info earlier in the trek. (Didn't work)

I was shot gunning it. What can I say???

PHV... F1 key was used and abused as well as half a dozen websites and 30 posts on this one. Micorsoft help most of the time is not much help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top