VB6 using a Listbox selected value in a query

I have a VB6 script behind a form.  Form contains a listbox (lstGuiParm) and a text box (txtBox).  When the user selects a value from lstGuiParm, I want to construct a sql lookup.

But something's not correct in my WHERE clause.
Private Sub lstGuiParm_Click()
   Dim fsCmd as String

   fsCmd = "SELECT StatusCd from GuiParmList WHERE ParmNm = '" &  **SELECTEDVALUE GOES HERE** & "'"
   Set goRecSet = goConn.Execute(fsCmd)
...
End Sub

Open in new window

kkbenjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rushtoshankarSr Manager Software DevelopmentCommented:
Problem is with single quotes. Please check the following link

http://www.tek-tips.com/viewthread.cfm?qid=1461215
0
rushtoshankarSr Manager Software DevelopmentCommented:
fsCmd = "SELECT StatusCd from GuiParmList WHERE ParmNm = " & Replace(**SELECTEDVALUE GOES HERE**, "'", "'")
0
kkbenjAuthor Commented:
What I need an answer on is how to reference the selected row value from the list box.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

rushtoshankarSr Manager Software DevelopmentCommented:
fsCmd = "SELECT StatusCd from GuiParmList WHERE ParmNm = " & Replace(lstGuiParm.List(lstGuiParm.Selected), "'", "'")
0
kkbenjAuthor Commented:
.Selected

is highlighted with this error:
Compile error:
Argument not optional
0
rushtoshankarSr Manager Software DevelopmentCommented:
a small correction.Make it simple
fsCmd = "SELECT StatusCd from GuiParmList WHERE ParmNm = " & Replace(lstGuiParm.Text, "'", "'")

set the lstGuiParm.Multiselect = false (do it if you want to force the user to select only one item at a time)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kkbenjAuthor Commented:
That's perfect.  And how do I assign it to the value displayed in the text box?
0
rushtoshankarSr Manager Software DevelopmentCommented:
>> And how do I assign it to the value displayed in the text box?
slightly confusing.
Do you want to display the value stored in fsCmd variable in the text box ?

txtBox.Text = fsCmd
0
kkbenjAuthor Commented:
sorry for not being clear.  

once I have retrieved the data from the database, I want to display the info in the text box (txtBox) on the form.

txtBox.text = goRecSet("StatusCd")
says Compile error:
Method or data member not found
0
kkbenjAuthor Commented:
The textbox assignment didn't work because it was a control array.  fixed.

Thanks for the help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.