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

x
?
Solved

obtain value from selected listbox item

Posted on 2014-01-03
3
Medium Priority
?
416 Views
Last Modified: 2014-01-03
Folks

I have listbox with values, if I click on the selected value I get a message showing the depicted list box item from the list  i.e. like so:


Private Sub ListBox1_Click()
MsgBox "Selected Value is " & ListBox1.Value & ""


1) how do I get the select value to display in an excek worksheet i.e. on sheet 1 field b1?
2) how do I get a listbox1.value to display and parse in SQL statement on a DB connection i.e.:

 strSQL = "SELECT * FROM MYTABLE WHERE PARAMETER = ListBox1.Value  ?

would be glad for your assistance

cheers
0
Comment
Question by:rutgermons
[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
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
rspahitz earned 2000 total points
ID: 39754933
Since the correct value is appearing, you should be able to do this to add it to Excel:

Sheets(1).range("B1").value = ListBox1.Value

Open in new window


And to add it to SQL:

strSQL = "SELECT * FROM MYTABLE WHERE PARAMETER = " & ListBox1.Value

Open in new window


(This if PARAMETER is numeric)
or

strSQL = "SELECT * FROM MYTABLE WHERE PARAMETER = '" & ListBox1.Value & "'"

Open in new window

(This if your PARAMETER is a string rather than a number.)
0
 

Author Comment

by:rutgermons
ID: 39755012
the paramtere could be dates too! the above seem nearly there but doesnt display on the below (this is the selected value in the valuelist)


"Backlog 01208 - Backlog request thru 12/08/13"
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 39755514
For dates you want to use "#" as delimiters, I think:

strSQL = "SELECT * FROM MYTABLE WHERE PARAMETER = #" & ListBox1.Value & "#"

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

721 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