Jana,
hrm. i almost have it working. this is my new expression:
=DCount("*","tblcontactdata","[date] Between #" & [txtboxstartdate] & "# And
#" & [txtboxenddate] & "# AND [upsource]=" & Chr(34) & Forms!formquerybuilder!
cboxupsource & Chr(34) & " AND [department]=" & Chr(34) & Forms!
formquerybuilder!cboxdepartment & Chr(34))
first, let me say that my use of chr(34) instead of the single-quote method
is not a reflection on you or your answer, but just lets me see more clearly.
this is something i saw in other posts while looking for answers to my
problem. to me, '" looks too close to "' for my taste.
anyhow, it seems to work fine. except that (and i forgot to mention this
earlier) these fields may be null (only the start and end dates are required).
the form that creates the report doesn't NEED the user to specify a
department. if no department is specified, the report runs on a combined
department total. how can i get this to work with an idea similar to:
iif(isnull(forms!formquerybuilder!cboxdepartment=t rue),"","[department]=" &
Chr(34) & Forms!formquerybuilder!cboxdepartment & Chr(34) &)
that way, if the field is null, the expression would look like this:
[date] between #10/1/05# and #11/30/05# and ""
the idea being that concatenating the where clause with "" will do nothing
but if the department IS specified, then it would look like this:
[date] between #10/1/05# and #11/30/05# and [department]="Electronics"
the same would go for upsource as well. i hope i explained everything so it
makes sense.
Jana wrote:
Try this instead:
=DCount("*","tblcontactdata","[date] Between #" & [txtboxstartdate] &
"# And #" & [txtboxenddate] & "# AND [upsource]='" &
forms!formquerybuilder!cboxupsource &
"' AND [department]='" forms!formquerybuilder!cboxdepartment & "'")
Some notes about figuring out the proper syntax:
1. Date values must be wrapped with # signs, which you did properly.
ex: [date] = #01/01/2005#
2. Text values must be wrapped with ' signs (single quotes).
ex: [upsource] = 'my source'
You had single quotes around the field names [upsource] and
[department] which were unnecessary, as well as around the AND after
the txtboxenddate.
3. Numerical values do NOT require any wrapping.
ex: [MyNumber] = 12
4. When referring to the value of a field on a form or report, do
not put single quotes around them, or the function will put the text
within the quotes rather than the value of the field.
ex: If the cboxupsource field has text in it:
"[upsource] = '" & forms!fromquerybuilder!cboxupsource & "'"
(note the placement of the single quotes and double quotes)
Hope that helps,
Jana
If the cboxupsource field as a number in it:
"[upsource] = " & forms!formquerybuilder!cboxupsource
If the cboxupsource field has a date in it:
"[upsource] = #" & forms!formquerybuilder!cboxupsource & "#"
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200511/1