Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

value and text in combo Excel vba

Posted on 2006-07-10
10
Medium Priority
?
2,160 Views
Last Modified: 2008-01-09
Hello,

I want to know if it's possible to assign value and text information to a combo in vba to show the text and make the queries with the value.

Thanks in advance.
0
Comment
Question by:nuberun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
10 Comments
 
LVL 7

Expert Comment

by:assyst
ID: 17072750
If your value field is a number field. you can set the text by using the additem method and
you can set the value data using the itemdata of a combobox

eg.

   Combo1.AddItem "Assyst"
   Combo1.ItemData(Combo1.NewIndex) = 1

if your value field is not a number field. you can make use of a string array and get the
required value data in the click event using the listindex as the array index.

Good Luck
0
 
LVL 7

Expert Comment

by:assyst
ID: 17072772
Addition to above comment

You can get the value item by

1st method using the itemdata
     dim x
           x = combo1.itemdata(combo1.listindex)
2nd method
    suppose arrlist is the string array
    dim x
          x = arrlist(combo1.listindex)
 
Hope this will serve the purpose
0
 

Author Comment

by:nuberun
ID: 17073026
Hi,

Thanks for your assistance but I don't have the itemdata property in the combo box.

Regards
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Expert Comment

by:assyst
ID: 17073585
Ur application is in Visual Basic right..
0
 

Author Comment

by:nuberun
ID: 17073662
This part is in Excel, using vba. In vb.net there is the option to assign the value and text to be displayed. I want to be able to do the same in Excel vba.
Thanks for your help
0
 
LVL 15

Accepted Solution

by:
dave4dl earned 1000 total points
ID: 17074445
Maintain an array of "behind-the-scenes" values that parallels the indices of the combo box.  Then when you need to access the value (not the displayed text) pull from the array using the index of the selected item in the combo box.

Or you could maintain your list of values in excel and access with vlookup (see http://www.exceltip.com/st/Add_Combo_Box_to_a_Sheet_in_Microsoft_Excel/300.html)
0
 
LVL 15

Expert Comment

by:dave4dl
ID: 17228832
I believe my post answers the question (conceptual answer as well as a link)
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn different types of Android Layout and some basics of an Android App.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Progress

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question