Solved

obtain value from selected listbox item

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

914 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

13 Experts available now in Live!

Get 1:1 Help Now