Solved

obtain value from selected listbox item

Posted on 2014-01-03
3
410 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
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
rspahitz earned 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

820 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