Problem with Expression

R

Rene

Good afternoon,

I have a parent form with 2 list boxes and 2 text boxes that supply
information to an expression located within a calculated control in a
subform.

ListBox 1 name is: [FilterCompany]
ListBox 2 name is: [FilterDivision]
TextBox 1 name is: [FilterBeginDate]
TextBox 2 name is: [FilterEndDate]

Because both Company and Division have their own table, in order to factor
these two into the count, I pull the information from a query where the two
tables are joined to an Injury Illness table.

The expression located with the calculated control in the subform is:

=Format(DCount("[InjuryIllnessCaseNumber]","qryInjuryIllnessCases","[InjuryIllnessCaseDate]<=[Forms]![frmIncidentsDataRetrievalScreen]![FilterEndDate]
And
[InjuryIllnessCaseDate]>=[Forms]![frmIncidentsDataRetrievalScreen]![FilterBeginDate]
And ([InjuryIllnessCaseClassificationID]=2 or 8 or 5) And
([EstablishmentCompanyID]=[Forms]![frmIncidentsDataRetrievalScreen]![FilterCompany])
And
([EstablishmentDivisionID]=[Forms]![frmIncidentsDataRetrievalScreen]![FilterDivision]) "),"#,##0")

The expression works fine, but I have to select an option from each list
box, otherwise it will not count the records. What I would like to do is:

1) If I do not select an option from any list box, I want the expression to
disregard the list boxes and return a count based only on the date range. In
other words, the expression will include all records.

2) Be able to select multiple options from the list box and have those
factored into the expression. The current expression only allows me to select
one option and factor in only that one option.

Formats:

ListBox format is Number. Company A is 1, Company B is 2, etc.
Division A is 1, Division B is 2, etc.

TextBox is Date.

Thanks in advance for your help,

Rene
 
T

Tom Wickerath

Hi Rene,

I think I would abandon the use of DCount here. Instead, I would use VBA
code to create the appropriate SQL (Structured Query Language) statement
on-the-fly. You can then open a DAO recordset, rs, in code, using this query.
If the recordcount is > 0, then issue a MoveLast command, followed by
rs.RecordCount. (You must move to the last record in a DAO recordset, in
order to get an accurate count).

To allow more than one selection in a list box, you must set the Multi
Select property to either Simple or Extended, and use VBA code to "iterate"
the .ItemsSelected property. You won't find this property in the Properties
sheet. I have some QBF (Query By Form) samples that show the technique of
iterating at listbox. The simplist example is the Elements sample:

http://www.accessmvp.com/TWickerath/downloads/elements.zip

http://www.accessmvp.com/TWickerath/downloads/Chap08QBF.zip

http://www.seattleaccess.org/downloads.htm
See the download "Query By Form"
Tom Wickerath, February 12, 2008

The sample available on the Seattle Access web site includes a Word document
that attempts to explain how the technique works.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________

Rene said:
Good afternoon,

I have a parent form with 2 list boxes and 2 text boxes that supply
information to an expression located within a calculated control in a
subform.

ListBox 1 name is: [FilterCompany]
ListBox 2 name is: [FilterDivision]
TextBox 1 name is: [FilterBeginDate]
TextBox 2 name is: [FilterEndDate]

Because both Company and Division have their own table, in order to factor
these two into the count, I pull the information from a query where the two
tables are joined to an Injury Illness table.

The expression located with the calculated control in the subform is:

=Format(DCount("[InjuryIllnessCaseNumber]","qryInjuryIllnessCases","[InjuryIllnessCaseDate]<=[Forms]![frmIncidentsDataRetrievalScreen]![FilterEndDate]
And
[InjuryIllnessCaseDate]>=[Forms]![frmIncidentsDataRetrievalScreen]![FilterBeginDate]
And ([InjuryIllnessCaseClassificationID]=2 or 8 or 5) And
([EstablishmentCompanyID]=[Forms]![frmIncidentsDataRetrievalScreen]![FilterCompany])
And
([EstablishmentDivisionID]=[Forms]![frmIncidentsDataRetrievalScreen]![FilterDivision]) "),"#,##0")

The expression works fine, but I have to select an option from each list
box, otherwise it will not count the records. What I would like to do is:

1) If I do not select an option from any list box, I want the expression to
disregard the list boxes and return a count based only on the date range. In
other words, the expression will include all records.

2) Be able to select multiple options from the list box and have those
factored into the expression. The current expression only allows me to select
one option and factor in only that one option.

Formats:

ListBox format is Number. Company A is 1, Company B is 2, etc.
Division A is 1, Division B is 2, etc.

TextBox is Date.

Thanks in advance for your help,

Rene
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top