Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Select with VB controls parameteres

Status
Not open for further replies.

ringobingo

Technical User
Aug 23, 2000
2
0
0
GB
Hi,
Kind of new at this so here goes, i have these list box's filled with only distinct values from colums in an access database. These Distinct values are from a simple Select Distinct qry. I have then created a
Select qry like below so user can pull what the want from a VB form

sExecutestring = "Select * From Carsdb"
"Where FirstColumn = '"ListBox.List(Listbox.ListIndex) & "'" "And SecondColumn = '"ListBox1.List(Listbox1.ListIndex) = SecondColumn & "'" etc

I have a few questions that i would be greatful for their answers, - Can i use these two select queries in this way?
and what is the correct syntax for the Where section.

As it stands i have this query set, that looks cool in all the text and material gathered but i still get this Error

Run Time Error --2147217900
Syntax Error in From Clause

Cheers

Andy
 
Hi there RingoBingo!

I Don't if I'm wrong but I think is something is missing in your SQL.

1st line:
sExecutestring = "Select * From Carsdb[put a space here]"

second line:
"Where FirstColumn = '"ListBox.List(Listbox.ListIndex)
third line:
& "'" "And SecondColumn = '"ListBox1.List
forth line:
& "'" "[put 'and' here](Listbox1.ListIndex) = SecondColumn & "'" etc

I not a user of VB(so I can make a mistake) but in Delphi it's like this:

sExecutesString:= 'select * from Cardb ' +
'Where FirstColumn='+ IntoToStr(ListBox.ItemIndex) ' +
'And SecondColumn='+ IntoToStr(ListBox1.ItemIndex)'...etc


I Try :)
 
fluzzi is right, your syntax is a little off. Here is how you need to format it. You were missing some spaces and &'s.

sExecutestring = "Select * From Carsdb Where FirstColumn = '" & ListBox.List(Listbox.ListIndex) & "'" & " And SecondColumn = '" & ListBox1.List(Listbox1.ListIndex)& "'"

 
You might also want to try a stored procedure with the input parameters that you need. Although how you work with stored procedures in VB, I don't know (it may be more trouble than it is worth).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top