Help in writing SQL statement

S

Silvio

I have a query with a cityID field. I am trying to exclude cityID=1 only if
"MyForm OfficeID is = 3".

In short: if Forms![frmWelcome]![OfficeID] = 3 then CityID > 1 esle all
cities ID are included.

I would like to include this statement in the criteria under CityID and I am
not familiar with SQL statements syntax.

Thanks for your help.
 
L

Lord Kelvan

you need to place

Forms![frmWelcome]![OfficeID]

as a field

so theofficeid: Forms![frmWelcome]![OfficeID]

and have a criteria of = 3 and then another field

cityid and have on the same line a criteria >1

and on the line under that have for the officeid <>3

so it will look like

field theofficeid: Forms![frmWelcome]![OfficeID] cityid
....
....
Criteria
"3" >1
or <>"3"

and that should do it

Regards
Kelvan
 
S

Silvio

If I understand you correctly this is what I have and it is not working, it
gives me ALL the records


SELECT tblHolds.HoldID, tblAddress.OfficeID, [Forms]![frmWelcome]![OfficeID]
AS TheofficeID, tblAddress.CityID
FROM tblAddress INNER JOIN tblHolds ON tblAddress.AddressID =
tblHolds.AddressID
WHERE (((tblHolds.HoldID)=1) AND ((tblHolds.DispoID) Is Null) AND
((tblAddress.OfficeID)=[Forms]![frmWelcome]![OfficeID]) AND
(([Forms]![frmWelcome]![OfficeID])=3) AND ((tblAddress.CityID)>1)) OR
((([Forms]![frmWelcome]![OfficeID])<>3));



My standard WORKING codes is:

SELECT tblHolds.HoldID, tblAddress.OfficeID
FROM tblAddress INNER JOIN tblHolds ON tblAddress.AddressID =
tblHolds.AddressID
WHERE (((tblHolds.HoldID)=1) AND ((tblHolds.DispoID) Is Null) AND
((tblAddress.OfficeID)=[Forms]![frmWelcome]![OfficeID]));


What I need is: if the officeID located in ([Forms]![frmWelcome]![OfficeID])
is 2 or 3 then records with cityID = 6 should be excluded. If not only the
code above is true.
 

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