View Full Version : Complicated?


Paul Cooke
10-16-2001, 08:44 AM
I think this may be complicated but if you don't ask!!!....

I have a from called "Treatment Form" in it, it has a number of fields including one call "Company". At the bottom it has 10 sets of fields for medication issued and the quantity (Separate fields) to a company. Each field is numerically named Con1 & Qty1, Con2 & Qty2 etc.. I also have a check box at the end of the form which is called "Checked"

What I want to do is run a report that lists all the medications issued and the quantities
to a particular company in total but ingnoring forms with a tick in the check box?

I hope this is not to confusing and possbile?

Thanks

D.Mair
10-19-2001, 06:36 AM
Yes well I think so.

Set up a Query
Place all the field in it. i.e. Company Con1 Qty1 Con2 Qty2 and the check box field

set the criteria for the Company field to

[Forms]![Treatment Form]![Company]

that will only select one company and set the check box field criteria to

No

Save the Query and then create a report on it

That I think should do it.
Although I am no expert.

Pat Hartman
10-20-2001, 06:36 PM
There is a basic concept problem with your table structure. You have a many-to-many relationship - many companies to many medications. To properly represent this structure, you need three tables. A company table, a medication table, and a relation table. The relation table includes CompanyId and MedicationId as its primary key and includes quantity as a data field. This will allow you to issue an unlimited number of medication types to any company rather than just the ten you have allowed for. Once you change the structure (you'll also need to change your form to a form with a subform), a simple totals query will provide the answer you need.

Select CompanyId, MedicationId, Sum(MedQuantity) As SumOfQuantity
From YourTable
Where CompanyId = [Enter Company Id] And Checked = 0
Group by CompanyId, MedicationId;

If you don't restructure your table, you'll need to "normalize" it on the fly with a union query that selects each of the 10 medication and quantity fields separately.