Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Visual Basic  Combobox

Posted on 2002-07-08
5
Medium Priority
?
262 Views
Last Modified: 2013-11-25
I have created a combobox on my form.  I have added four items to the combobox.  Once one of these items in the combobox is clicked, I need a textbox to be populated with a price associated with the item in the combobox.  I am using a select case statement in the combobox click event to accomplish this.  Is this the right direction to go?  How can I get the selected item from the combobox to send a message to the textbox once it is clicked?
Thanks
0
Comment
Question by:scitesy
[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
5 Comments
 
LVL 101

Accepted Solution

by:
mlmcc earned 200 total points
ID: 7138852
Yes, you are thinking along the correct lines.  

There are two ways to do this.  If you are using a database, tie the textbox to a datasource or create a recordset in code.  The SQL will look something like

ADODC1.RecordSource = "SELECT price FROM MyData WHERE MyData.ItemName = '" & Me.ComboBox.Text & "'"
ADODC1.Refresh

If it hardcoded in code
SELECT CASE Me.ComboBox.Text
Case "ITEM1" Me.textBoxPrice= 3.50
Case "ITEM2" Me.textBoxPrice = 4.50
' One case for each item
.
.
.
end select

good luck
mlmcc
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7138906
Personally, if there's no database in use, I'd load all prices into a module-level array variable.  On click in the combobox, take the price from the array and place into the textbox (although a label might be better if the price cannot be changed.)

Private m_curPriceArray() as Currency

Private Sub Combo1_Click()
  Text1.Text = m_curPriceArray(Combo1.ListIndex)
End Sub

Private Sub Form_Load()
  ' fill combo with items, and array with prices
  ReDim m_curPriceArray(3)

  Combo1.AddItem "Item1"
  m_curPriceArray(0) = 17.34

  Combo1.AddItem "Item2"
  m_curPriceArray(1) = 23.95

  Combo1.AddItem "Item3"
  m_curPriceArray(2) = 19.45

  Combo1.AddItem "Item4"
  m_curPriceArray(3) = 9.95
end sub

0
 
LVL 3

Expert Comment

by:Bahnass
ID: 7139730
Or if U has DBase in use (storing Items, Prices)
U can make use of   itemdata Property of combobox to hold Unique ID of item record
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7991238
Hi scitesy,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept mlmcc's comment(s) as an answer.

scitesy, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 8053220
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

604 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