Solved

obtain value from selected listbox item

Posted on 2014-01-03
3
406 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now