SQL Syntax

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have this code :

Set Q = db.QueryDefs("qrySearch")
Q.sql = "SELECT qryEmployee.EmpID, qryEmployee.FirstName,
qryEmployee.LastName, qryEmployee.Country, qryEmployee.Region, " & _
"tblEmployee.RegionID FROM qryEmployee WHERE (((tblEmployee.RegionID) In ("
& Me.RegionSelected & ")));"

Q.Close

This is code from Allen Browne I believe.

This creates a query that allows multiple values to be passed to it - e.g
select all employees dependant on what region they are in - I can choose
multiple regions - this works fine.

What I need to know is if I also want to add additional fields to the query
when it is created based on multiple selections then what would the syntax be.

How do I add :

"tblCountry.CountryID FROM qryEmployee WHERE (((tblEmployee.CountryID) In ("
& Me.CountrySelected & ")))

I keep getting a syntax error.

I want to be able to then filter the query by Countries selected and then I
will want to do it by group etc. So essentially I am building a query based
on my selections in multi-select list boxes.
 
Hmm,

Are you sure the first part works?
I can't see how qryEmployee and tblEmployee are linked.

Anyway, to sort out the SQL for adding items, take the first query, open
it in query design view, add the additional items, then switch to SQL
view and copy/paste the new SQL as required.

Regards,
Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top