W
Wayne Morgan
Nice website, thanks for the link.
Ok, I'm just going to take a guess here.
While you can refer to a control on a form for the parameter, the "value" of
the control will go in as the limiter. The query won't act on the text in
the control if that text is an expression. To do that, you would need to
change the .SQL property of the control to concatenate in the text.
Example:
If the control's value is
Between 'A' And 'C'
and you placed this under a field called [Field1], this wouldn't filter
field1 for records between A and C. Instead, the resulting SQL would look
like:
WHERE [Field1]=[Forms]![MyForm]![MyControl]
which would be equivalent to:
WHERE [Field1]="Between 'A' And 'C'"
In other words, it would be trying to find the string listed as the value of
Field1, not what the string represents.
To work around this, you need to concatenate together the SQL in the code
behind the form then apply that to the .SQL property of the query.
Example:
CurrentDb.QueryDefs("qryMyQuery").SQL = strBuiltSQL
--
Wayne Morgan
MS Access MVP
Ok, I'm just going to take a guess here.
While you can refer to a control on a form for the parameter, the "value" of
the control will go in as the limiter. The query won't act on the text in
the control if that text is an expression. To do that, you would need to
change the .SQL property of the control to concatenate in the text.
Example:
If the control's value is
Between 'A' And 'C'
and you placed this under a field called [Field1], this wouldn't filter
field1 for records between A and C. Instead, the resulting SQL would look
like:
WHERE [Field1]=[Forms]![MyForm]![MyControl]
which would be equivalent to:
WHERE [Field1]="Between 'A' And 'C'"
In other words, it would be trying to find the string listed as the value of
Field1, not what the string represents.
To work around this, you need to concatenate together the SQL in the code
behind the form then apply that to the .SQL property of the query.
Example:
CurrentDb.QueryDefs("qryMyQuery").SQL = strBuiltSQL
--
Wayne Morgan
MS Access MVP
Jeff C said:I followed a suggestion from a post made by an MVP which referenced Michael
Green's article "Customizing Access Parameter Queries" ...
http://www.fontstuff.com/access/index.htm.
My unbound form/dialog has a combo box for the director which points to a
query matching "many" depts....to each director. This functions fine.
The second combo box points to a single column table with three rows, each
row holding an expression as referenced earlier. These expressions, if
pasted into the Criteria: for [Current TB Test Date], individually result
in
a correctly functioning query. When the Criteria: is changed through the
"build" function pointing to my frm...combo box...the query results in an
empty report. Hope this is enough info, details are below. I am baffled.
I also can't express enough appreciation, each struggle with this is a
great
learning experience. Thanks
Unbound form: frmReportMenu: Combo Box Properties
Name: cboReports
Control Source: empty
Format: empty
Row Source Type: Table/Query
Row Source: SELECT [tblReports].[Exp] FROM [tblReports];
Column Count: 1
Column Head: No
Bound Column: 1
OK Button
Private Sub cmdCancel_Click()
DoCmd.Close acForm, "frmReportMenu"
End Sub
Private Sub cmdOK_Click()
DoCmd.OpenReport "1_arptquerytest", acViewPreview, acEdit
DoCmd.Close acForm, "frmReportMenu"
End Sub
tblReports: Single column table
Field Name: Exp
Data Type: Text
Field Size: 255
Default Display Control was Text Box, I also tried Combo Box which didn't
work so it is now Text Box
1_arptQueryTest
Record Source: qryBiannualTests
qryBiannualTests SQL
PARAMETERS [Forms]![frmReportMenu]![cboReports] DateTime;
SELECT [All Employees].Last, [All Employees].First, [Child Query].[Current
TB Test Date], qryDirectorAssignments.[Acct #]
FROM tblReports, (([All Employees] INNER JOIN [Child Query] ON [All
Employees].ID = [Child Query].ParentTable_ID) INNER JOIN
qryDirectorAssignments ON [Child Query].Dept =
qryDirectorAssignments.[Acct
#]) INNER JOIN tblDirectorsList ON qryDirectorAssignments.Name =
tblDirectorsList.Name
WHERE ((([Child Query].[Current TB Test
Date])=[Forms]![frmReportMenu]![cboReports]) AND
((tblDirectorsList.Dir_ID)=[Forms]![frmReportMenu]![cboDirectors]) AND
(([Child Query].Active)=Yes));