C
cprav
I initially posted this question in the Reports forum as my subquery is
creating a filtered report. However, I just can't seem to get this subquery
down, and now that I know what it is I'm trying to accomplish (I had never
even heard of subqueries when I posted my initial question) I thought I would
post here. I apologize if this is out of line.
Here is the info on my database:
It is a database with information on various organizations.
The main report has "Organization Name" and "County" fields.
Because each organization may have several offices, there is a
subform/report for Location. Included is a Community field to show which
area of the county the office/location is in.
Next, to make this way user friendly, I have created a dialouge box where
the user chooses from a list of counties which populates the community list.
This is working fine. The user then clicks a button to view all the
organizations in the chosen community.
To save myself from creating several extra reports (which are quite complex
with several subforms) I have linked the button to a macro which runs the
Report with a filter. Other such buttons I have set up (based on the main
report) have worked fine, but of course, this is a bit tricker as it's a
subform.
This is the subquery I have created (I've played around with it a lot so I
can't remember how it started out, but this is what it looks like now!)
Dim strWhere As String
strWhere = "EXISTS (SELECT Community FROM Locations " & _
"WHERE ((Locations.community = " & [choosecom] & ") " & _
"AND (CommunityInventory.OrgID = Locations.OrgID)))"
DoCmd.OpenReport "CommunityInventory", acViewPreview, strWhere
The code *does* bring up my report, but it is *not* filtered - it shows all
records.
I was advised of the 'immediate' window...thing (not big on technical
terms!!) this is what comes up:
EXISTS (SELECT Community FROM Locations WHERE ((Locations.community =
Bridgetown) AND (CommunityInventory.OrgID = Locations.OrgID)))
I've been told the last "Locations.OrgID" should be a number. (not sure why)
I've tried every combination I can think of, but it just won't work. I'm
about ready to give up, but this filter is very important and I'm not sure
how else to get the information I want (i.e. all the organizations in a given
community) without having to create a seperate records for each seperate
office (which would be a lot of wasted time in many cases - many
organizations have quite a few locations and there is a lot of information in
this database associated with each organization).
ANY help would be greatly appreciated! I've been trying to get this work
for almost 2 weeks and I really need to get this database back to the users!
Thank you!
creating a filtered report. However, I just can't seem to get this subquery
down, and now that I know what it is I'm trying to accomplish (I had never
even heard of subqueries when I posted my initial question) I thought I would
post here. I apologize if this is out of line.
Here is the info on my database:
It is a database with information on various organizations.
The main report has "Organization Name" and "County" fields.
Because each organization may have several offices, there is a
subform/report for Location. Included is a Community field to show which
area of the county the office/location is in.
Next, to make this way user friendly, I have created a dialouge box where
the user chooses from a list of counties which populates the community list.
This is working fine. The user then clicks a button to view all the
organizations in the chosen community.
To save myself from creating several extra reports (which are quite complex
with several subforms) I have linked the button to a macro which runs the
Report with a filter. Other such buttons I have set up (based on the main
report) have worked fine, but of course, this is a bit tricker as it's a
subform.
This is the subquery I have created (I've played around with it a lot so I
can't remember how it started out, but this is what it looks like now!)
Dim strWhere As String
strWhere = "EXISTS (SELECT Community FROM Locations " & _
"WHERE ((Locations.community = " & [choosecom] & ") " & _
"AND (CommunityInventory.OrgID = Locations.OrgID)))"
DoCmd.OpenReport "CommunityInventory", acViewPreview, strWhere
The code *does* bring up my report, but it is *not* filtered - it shows all
records.
I was advised of the 'immediate' window...thing (not big on technical
terms!!) this is what comes up:
EXISTS (SELECT Community FROM Locations WHERE ((Locations.community =
Bridgetown) AND (CommunityInventory.OrgID = Locations.OrgID)))
I've been told the last "Locations.OrgID" should be a number. (not sure why)
I've tried every combination I can think of, but it just won't work. I'm
about ready to give up, but this filter is very important and I'm not sure
how else to get the information I want (i.e. all the organizations in a given
community) without having to create a seperate records for each seperate
office (which would be a lot of wasted time in many cases - many
organizations have quite a few locations and there is a lot of information in
this database associated with each organization).
ANY help would be greatly appreciated! I've been trying to get this work
for almost 2 weeks and I really need to get this database back to the users!
Thank you!