WHERE clause in SQL

  • Thread starter Slez via AccessMonster.com
  • Start date
S

Slez via AccessMonster.com

I have a form that imports data and was working fine until I added another
criteria to the WHERE clause. Originally I had:
strDetailSQL = strDetailSQL + " WHERE (((Project.JobNumber)=Forms!
frmImportNewProject!NewProject));"

I then changed to:
strItemSQL = strItemSQL + " WHERE (((Project.JobNumber)=[Forms]!
[frmImportNewProject]![NewProject]) AND ((Bid.BidStatus)="Awarded"));"

I keep getting compile errors having to do with the end of the statement. I
think it is due to the parentheses, but haven't been able to correct it by
trying different combinations. The first thing I did was remove one of the
parentheses after "Awarded", but I got the same message. When I look at how
it is laid out, it seems like it should work.

Any help is appreciated!
 
R

Rick Brandt

Slez said:
I have a form that imports data and was working fine until I added
another criteria to the WHERE clause. Originally I had:
strDetailSQL = strDetailSQL + " WHERE (((Project.JobNumber)=Forms!
frmImportNewProject!NewProject));"

I then changed to:
strItemSQL = strItemSQL + " WHERE (((Project.JobNumber)=[Forms]!
[frmImportNewProject]![NewProject]) AND ((Bid.BidStatus)="Awarded"));"

I keep getting compile errors having to do with the end of the
statement. I think it is due to the parentheses, but haven't been
able to correct it by trying different combinations. The first thing
I did was remove one of the parentheses after "Awarded", but I got
the same message. When I look at how it is laid out, it seems like
it should work.

Any help is appreciated!

Access is fairly "parenthesis crazy" when you build quieries in the query
designer, but lots of times you don't need them at all. Try your where
clause with no parenthesis and it should work. About the only time you NEED
them is when you have multiple "AND" and "OR" clauses that need specific
grouping to work as desired. For your simple AND you shouldn't need any.
 
K

Ken Snell \(MVP\)

Use ' characters for string values when concatenating SQL statements into a
variable (see what I did with the Awarded portion):

strItemSQL = strItemSQL + " WHERE (((Project.JobNumber)=[Forms]!
[frmImportNewProject]![NewProject]) AND ((Bid.BidStatus)='Awarded'));"
 
S

Sylvain Lafontaine

You forgot to double your quotes inside the string:

.... AND ((Bid.BidStatus)=""Awarded""));"
 

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

Top