P
Pete
I have a report that takes a filter condition from a combo box on a form. The
combo box is populated from a table using a UNION query that adds an ‘All’
option. The first column is bound to the control and is hidden.
NoteAlike and % are used in place of Like & * as the database is written
in SQL compatible mode in anticipation of a future upgrade)
Combo Box Source
SELECT DISTINCT "%" as iStudyStatusID, "(All Study Statuses)" as
cStudyStatus FROM tlkpStudyStatus
UNION
SELECT DISTINCT tlkpStudyStatus.iStudyStatusID, tlkpStudyStatus.cStudyStatus
FROM tlkpStudyStatus;
Query WHERE clause
…WHERE (tblStudy.iStudyStatusID ALike [Forms]![frmMyForm]![cboStudyStatus])…
This works fine. However, users have now requested the ability to select one
further option that combines 2 statuses. There is no need for a multiselect
list box. I have used the following to populate the combo box:
SELECT DISTINCT "%" as iStudyStatusID, "(All Study Statuses)" as
cStudyStatus FROM tlkpStudyStatus
UNION
SELECT DISTINCT "3 Or 4" as iStudyStatusID, "Reporting (Draft or Final)" as
cStudyStatus FROM tlkpStudyStatus
UNION
SELECT DISTINCT tlkpStudyStatus.iStudyStatusID, tlkpStudyStatus.cStudyStatus
FROM tlkpStudyStatus;
However, when the user selects "Reporting (Draft or Final)" the query does
not return any records. If you manually type ‘Alike 3 or 4’ into the query,
records are returned.
I guess it is because the control is returning a string value that needs to
be evaluated (I have tried various combinations using Eval and IIF
statements). I know I am being lazy doing it this way, but interested to know
if it can be done, as it is simpler than setting the report’s RecordSource
programmatically, as other combinations can be easily added without any need
for modifying code.
combo box is populated from a table using a UNION query that adds an ‘All’
option. The first column is bound to the control and is hidden.
NoteAlike and % are used in place of Like & * as the database is written
in SQL compatible mode in anticipation of a future upgrade)
Combo Box Source
SELECT DISTINCT "%" as iStudyStatusID, "(All Study Statuses)" as
cStudyStatus FROM tlkpStudyStatus
UNION
SELECT DISTINCT tlkpStudyStatus.iStudyStatusID, tlkpStudyStatus.cStudyStatus
FROM tlkpStudyStatus;
Query WHERE clause
…WHERE (tblStudy.iStudyStatusID ALike [Forms]![frmMyForm]![cboStudyStatus])…
This works fine. However, users have now requested the ability to select one
further option that combines 2 statuses. There is no need for a multiselect
list box. I have used the following to populate the combo box:
SELECT DISTINCT "%" as iStudyStatusID, "(All Study Statuses)" as
cStudyStatus FROM tlkpStudyStatus
UNION
SELECT DISTINCT "3 Or 4" as iStudyStatusID, "Reporting (Draft or Final)" as
cStudyStatus FROM tlkpStudyStatus
UNION
SELECT DISTINCT tlkpStudyStatus.iStudyStatusID, tlkpStudyStatus.cStudyStatus
FROM tlkpStudyStatus;
However, when the user selects "Reporting (Draft or Final)" the query does
not return any records. If you manually type ‘Alike 3 or 4’ into the query,
records are returned.
I guess it is because the control is returning a string value that needs to
be evaluated (I have tried various combinations using Eval and IIF
statements). I know I am being lazy doing it this way, but interested to know
if it can be done, as it is simpler than setting the report’s RecordSource
programmatically, as other combinations can be easily added without any need
for modifying code.