Solved

Visual Basic  Combobox

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

717 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