• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

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

0
kkbenj
Asked:
kkbenj
  • 5
  • 5
1 Solution
 
rushtoshankarCommented:
Problem is with single quotes. Please check the following link

http://www.tek-tips.com/viewthread.cfm?qid=1461215
0
 
rushtoshankarCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
rushtoshankarCommented:
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
 
rushtoshankarCommented:
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
 
kkbenjAuthor Commented:
That's perfect.  And how do I assign it to the value displayed in the text box?
0
 
rushtoshankarCommented:
>> 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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now