Solved

Visual Basic  Combobox

Posted on 2002-07-08
5
244 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 100

Accepted Solution

by:
mlmcc earned 50 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 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