Dear Marsh,
Thank you very much for your answer.
I'll explain what and why I try to do this.
I have a main report (of the main table) that contains
the name of the subjects that suits, the status of the
suit and so on. The sub report contains all the payments
that were made.
The sub report is built out of a query. Since I wasn't
able to check whether the user wanted to determine the
dates of the payments, I devided the query of the sub
report into 2 queries - one with a constraint on the date
field of the query and one without.
That's why I have 2 main reports - one for the constraint
query and one for the other.
I think I am going a round, I have been working on it for
days.... and after this long journey I got stuck.
The problem is that this is my first time with normalized
tables, and I probably made a lot of mistakes in the
reports.
I have a report, as I already mentioned, that contains
another sub report (for the payments).
I have the information for each record, and then I sum
all the subjects of the same organization and in the end -
the total sum.
In the "detail" of the report, I put the sub report that
is built on a query that summarize all the payments for
each suitID.
In the "Organization Footer", I put a report that is
built on another query that summarize all the payments
for each organization.
And in the "Report Footer", the same for all of the
records.
I open the main report using a script (after pressing a
button) which builds the MyCriteria and opens the report
using the following command:
DoCmd.OpenReport stDocName, acViewPreview, , MyCriteria.
BUT since only the suit detalis are shown in the main
report, in the query of the sub report I put the
constraints on the payments.
Since for the organization footer, I have another query,
it sums up all of the subjects in each organization,
without paying attention to the constraints of the main
report. For example, If I choose to make a report on a
specific organization, the total sum of all of the report
ignores this request, because it is built on another
query.
That's why I need to refer to the form, to check whether
the user wanted specific data and to put it in the
criteria of the query.
Please Please Please help me,
I don't know what to do.....
Thanks a lot a lot,
Sharon
-----Original Message-----
Sharon said:
In order to solve the problem I mentioned in my last
question, I tried to create a function that should return
the string with the criteria of the query and in the
criteria, I called this function.
The function looks like that:
Function GetDateCriteria()
If [Forms]![F_Menu]![DateV] = True then
GetDateCriteria = ">=[Forms]![F_Menu]![FromDate]
And <=[Forms]![F_Menu]![ToDate]"
Else
GetDateCriteria = "" 'I tried Null as well
End If
End Function
Before I get to your question, I want to mention that it is
easier for all involved if you would keep the messages about
a single question in a single thread. Creating a new thread
with your reply (to yourself) just leaves everyone (most
likely yourself included) wondering what went on before.
Now, to talk about your problem. What you posted above is a
little out of context (even considering the original
question), so it's not at all clear to me what you are
trying to accomplish. Regardless of what I understand about
your situation, I do not believe that two queries/reports
are required.
Unfortunately, your above approach is trying to simulate
what you type in the query design window (QBE). The actual
queries used anywhere in Access are really SQL statements.
The stuff you specify in the QBE is just a shorthand
convenience that Access translates into SQL (which you can
see by using the query's SQL view). When you are
constructing a query or its criteria in VBA code, you must
work within the rules of SQL.
Bottom line here is that I believe you can achieve your
objective, but all I can guess at this point is that you may
want to use a more complex arrangement in the query.
Possibly something like creating a calculated field.
TestDate: IIf(Forms!F_Menu!DateV = True, GetDateCriteria
Between Forms!F_Menu!FromDate And Forms!F_Menu!ToDate, True)
and set the calculated field's criteria to True
Beyond that raw idea, we'll need more background about the
queries and their criteria.