?
Solved

Visual Basic  Combobox

Posted on 2002-07-08
5
Medium Priority
?
254 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

801 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