質問

I haven't really found the answer I'm looking for anywhere, but I may not have looked hard enough.

Simply what I'm trying to do is run a VBA script that takes month and date from user input and from there runs two queries to gather the necessary information for a report.

    Query = "SELECT * FROM Chemicals WHERE ReportDate >= #" & BeginDate & "# AND ReportDate < #" & EndDate & "#;" _
    & "SELECT TotalWaterTreated FROM Flows WHERE ReportDate >= #" & BeginDate & "# AND ReportDate < #" & EndDate & "#;"

    ChemsQuery.SQL = Query

    DoCmd.OpenReport "Chemicals", acViewReport

This gives me an error and seems to be impossible to do it this way.

To help clarify my set up. The way I have my report designed is that it is set as a default to run to the query "ChemsQuery". This just seems to work well especially while working on the design of the report and printing reports.

If there is a different and better way to do this, I'm open to that. Specifically I'm just trying to figure out the best way to get all of this information into one report.

Also, I would prefer not to redesign my table set up in anyway seeing as there are already over 1000 lines of code that go into this project. Finding and changing all of that code is pretty much out of the question.

役に立ちましたか?

解決

Do the tables have any fields in common? If they do then the command you are looking for is JOIN. You should probably read up on it before proceeding. You can practice with JOINs in the graphical access query builder by draggin one field from a table to a field containing at least some of the same values in the other table(s). If the tables/queries aren't related by any fields but you have to have stuff from each in the same table/query result set, then UNION could be the answer you are looking for. Which you will also need to read up on. Or you could also do subreports in the main report, where for each totalwatertreated value you could subreport all chemicals, or vice-versa.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top