Link to home
Start Free TrialLog in
Avatar of kkbenj
kkbenj

asked on

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

Avatar of rushtoshankar
rushtoshankar
Flag of United States of America image

Problem is with single quotes. Please check the following link

http://www.tek-tips.com/viewthread.cfm?qid=1461215
fsCmd = "SELECT StatusCd from GuiParmList WHERE ParmNm = " & Replace(**SELECTEDVALUE GOES HERE**, "'", "'")
Avatar of kkbenj
kkbenj

ASKER

What I need an answer on is how to reference the selected row value from the list box.
fsCmd = "SELECT StatusCd from GuiParmList WHERE ParmNm = " & Replace(lstGuiParm.List(lstGuiParm.Selected), "'", "'")
Avatar of kkbenj

ASKER

.Selected

is highlighted with this error:
Compile error:
Argument not optional
ASKER CERTIFIED SOLUTION
Avatar of rushtoshankar
rushtoshankar
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kkbenj

ASKER

That's perfect.  And how do I assign it to the value displayed in the text box?
>> 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
Avatar of kkbenj

ASKER

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
Avatar of kkbenj

ASKER

The textbox assignment didn't work because it was a control array.  fixed.

Thanks for the help!