help on query for a report

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Can someone get me started in the right direction. I have 2 tables, one is
production the other is incoming_inventory. In production we have a fields
for ProductionDate PlantNo ShiftNO IngName1 IngName2 IngName3 IngName4
IngWeight1 IngWeight2 IngWeight3 IngWeight4 In my Incoming_Inventory
Table I have PurchaseDate IngName and IngWeight the forms used for both
these tables both use a combobox to look up the Ingredient from my
Ingredient_Table. Now the question. I need to keep a running inventory on a
daily basis for each ingredient. On any given day as an example IngName1 may
be Cement and on the next day IngName1 may be WhiteCement and IngName2 would
be Cement . I have a simple report that has incoming inventory totals for
each ingredient with totals for day , months and year but I am having
trouble with putting both outgoing and incoming together in one report.

Thanks
 
Bart said:
Hi,
Can someone get me started in the right direction. I have 2 tables, one is
production the other is incoming_inventory. In production we have a fields
for ProductionDate PlantNo ShiftNO IngName1 IngName2 IngName3 IngName4
IngWeight1 IngWeight2 IngWeight3 IngWeight4 In my Incoming_Inventory
Table I have PurchaseDate IngName and IngWeight the forms used for both
these tables both use a combobox to look up the Ingredient from my
Ingredient_Table. Now the question. I need to keep a running inventory on a
daily basis for each ingredient. On any given day as an example IngName1 may
be Cement and on the next day IngName1 may be WhiteCement and IngName2 would
be Cement . I have a simple report that has incoming inventory totals for
each ingredient with totals for day , months and year but I am having
trouble with putting both outgoing and incoming together in one report.

Thanks

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Your production table is not Normalized. You should not keep IngName1
thru IngName4 in one row. The table should be like this:

ProductionDate
PlantNo
ShiftNo
IngName
IngWeight

I'm not sure how you want your report set up, but you could get both
table's data sets into one query like this:

PARAMETERS this_date Date;

SELECT I.PurchaseDate, I.IngName,I.IngWeight, P.ProductionDate,
P.IngName, P.IngWeight

FROM Production As P LEFT JOIN Incoming_Inventory As I
ON P.ProductionDate = I.PurchaseDate

WHERE P.ProductionDate = this_date

If there is more data per date on the Incoming_Inventory side than the
Production side then switch the table names, Incoming_inventory would be
on the left side of LEFT JOIN. This will ensure that all the
Incoming_Inventory is shown w/ the production data.

The report would (hopefully) look something like this:

Inventory Production
------------------------------ --------------------------------
Date Ingredient Weight Date Ingredient Weight
------- ---------- ------ ------- ---------- ------
1/1/05 Cement 100 1/1/05 Cement 50
1/2/05 Cement 50
1/5/05 White Cement 1000 1/5/05 White Cement 100
1/6/05 White Cement 200

etc.


--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQ8wPmoechKqOuFEgEQLMogCeO5iVQROq7ZggZiYeE4AOag0wRgAAoNFp
Gi5hDAsxfctI8XdQZpquat6H
=Nsz/
-----END PGP SIGNATURE-----
 
Not knowing what you have in your fields, I had to kind of guess, but
something that jumped out at me was the occurrence of both [IngName1]
and [IngName4] in the same record.

[production] Table fields, including some apparently repeating groups:

ProductionDate
PlantNo
ShiftNO
IngName1
IngName2
IngName3
IngName4
IngWeight1
IngWeight2
IngWeight3
IngWeight4

From what you said, my guess is that they both contain the same kind of
stuff. So, I moved them and the [IngWeight...] fields to a separate
Table, as I illustrate below.

I also made some other changes, such as moving the names of materials to
a Table where they are listed just once, and other Tables make reference
to them via a linking key.

Incidentally, you never mentioned units of measure, so for simplicity I
just assumed they were all in kilograms (or tonnes, or ounces) and
omitted that part. If you DO have any different units, what I show here
won't work, and you'll have to convert all of them to compatible units
to do the arithmetic.

OK, first Table is a stripped-down version of your [Production] Table,
omitting all the repeating groups.

[Production] Table Datasheet View:

Production_ID PlantNo ProductionDate ShiftNO
------------- ------- -------------- -------
-2106329789 A 1/12/2006 1
346130729 A 1/13/2006 1
1585204936 A 1/12/2006 2

As I mentioned, I also put the ingredient names into a Table in which
each is mentioned only once. Other Tables needing to refer to "Cement"
use the key number 763168138 instead of the name "Cement"; this avoids
problems arising from misspelling it as "Cemnet" and not noticing the
mistake until after some wrong totals have been reported. Misspelling
the key number will likely cause an instant error message. (But I don't
expect that you will ever see or use the key numbers directly; the Combo
Boxes or other controls will display only the names.)

[Ingredient_Table] Table Datasheet View:

Ingredient_Table_ID Name
------------------- ----
-1292946867 WhiteCement
763168138 Cement

I created a new Table to list all the materials used during any shift
appearing in the [Production] Table. Its contents might look like this:

[Ingredients Used] Table Datasheet View:

Production_ID Ingredient_Table_ID IngWeight
------------- ------------------- ---------
-2106329789 763168138 3
346130729 -1292946867 10
346130729 763168138 10
1585204936 763168138 7

However, as I said, the key values aren't for human beings to look at,
so I defined a Lookup Query to display, instead of these meaningless
[Production_ID] values, a more usable name for each linked record in the
[Production] Table. This Lookup Query I defined thus:

[QL_Production] SQL:

SELECT Production.Production_ID,
[Production]![PlantNo] & " "
& [Production]![ProductionDate]
& "-" & [Production]![ShiftNO] AS Name
FROM Production
ORDER BY Production.PlantNo, Production.ProductionDate,
Production.ShiftNO;

The displayed names look like this, with the plant name ("A") followed
by date and shift. You could, of course, define this differently, to
display any meaningful name that both is short and uniquely identifies a
record in the [Production] Table.

[QL_Production] Query Datasheet View:

Production_ID Name
------------- --------------
-2106329789 A 1/12/2006-1
1585204936 A 1/12/2006-2
346130729 A 1/13/2006-1

To apply a lookup property to a foreign-key field, open the Table in
Table Design View, select the foreign key, select Lookup, and set the
properties as follows:
Display Control = List Box
Row Source = QL_Production
Column Count = 2
Column Widths = 0;1

I also applied a Lookup propery to the foreign key
[Ingredient_Table_ID], but in that case I looked up the name directly
from the [Ingredient_Table] Table. (Same as above, but set Row Source =
Ingredient_Table .)

With Lookup properties set on the foreign keys, the Table is much more
legible:

[Ingredients Used] Table Datasheet View:

Production_ID Ingredient_Table_ID IngWeight
------------- ------------------- ---------
A 1/12/2006-1 Cement 3
A 1/13/2006-1 WhiteCement 10
A 1/13/2006-1 Cement 10
A 1/12/2006-2 Cement 7

Warning: Some people dislike using Lookup properties because they hide
the fact that the fields actually contain the key numbers, not the names
that show up on the datasheet. So if that bothers you, don't use the
Lookup property. But I shall use them for all the foreign keys in my
examples here, such as in the following Table, showing materials
received into inventory. ([Ingredient_Table_ID] is a foreign key
referring to [Ingredient_Table], and I use a Lookup property here.)

[Incoming_Inventory] Table Datasheet View:

Incoming_ PurchaseDate Ingredient_ IngWeight
Inventory_ID Table_ID
--------- ------------ ----------- ---------
-1602432313 1/13/2006 WhiteCement 20
-1167407823 1/12/2006 Cement 30
-919687266 1/13/2006 Cement 15

Having moved the repeating groups out of the [Production] Table, the
Queries to track the changes to inventory for each type of material are
fairly simple. (OK, they appear a bit lengthy here, but just imagine
how spaghetti-like they'd be if you had to include special code for each
of the 4 "IngName/IngWeight" groups in the original Table! It would be
way more difficult to understand.)

First Query in this list grabs date, material, and weight from the
[Incoming_Inventory] Table. The key value, [Ingredient_Table_ID],
probably isn't needed, since I assume the material names are unique, but
it doesn't hurt anything to leave it in here. You don't need to look at
it. (If you do decide to remove it, you'll have to revise the later
Queries that depend on it.)

[Q_01 Incoming Inventory] SQL:

SELECT Incoming_Inventory.PurchaseDate,
Ingredient_Table.Name,
Sum(Incoming_Inventory.IngWeight) AS TotalWeight,
Ingredient_Table.Ingredient_Table_ID
FROM Ingredient_Table INNER JOIN Incoming_Inventory
ON Ingredient_Table.Ingredient_Table_ID
= Incoming_Inventory.Ingredient_Table_ID
GROUP BY Incoming_Inventory.PurchaseDate,
Ingredient_Table.Name,
Ingredient_Table.Ingredient_Table_ID;

So now we have a list of additions to inventory.

[Q_01 Incoming Inventory] Query Datasheet View:

PurchaseDate Name TotalWeight Ingredient_Table_ID
------------ ---- ----------- -------------------
1/12/2006 Cement 30 763168138
1/13/2006 Cement 15 763168138
1/13/2006 WhiteCement 20 -1292946867

We do the same for deductions from inventory, BUT I attached a minus
sign to them so that I could easily calculate totals.

[Q_02 Outgoing Inventory] SQL:

SELECT Production.ProductionDate,
Ingredient_Table.Name,
Sum(-[IngWeight]) AS TotalWeight,
Ingredient_Table.Ingredient_Table_ID
FROM Production INNER JOIN
(Ingredient_Table INNER JOIN [Ingredients Used]
ON Ingredient_Table.Ingredient_Table_ID
= [Ingredients Used].Ingredient_Table_ID)
ON Production.Production_ID
= [Ingredients Used].Production_ID
GROUP BY Production.ProductionDate,
Ingredient_Table.Name,
Ingredient_Table.Ingredient_Table_ID
ORDER BY Production.ProductionDate;

These fields are similar to those in the previous Query. (There's a
reason for making them match -- I want to combine all of them using a
Union Query.) The minus signs indicate that these values act to reduce
the inventory, instead of increasing it.

[Q_02 Outgoing Inventory] Query Datasheet View:

ProductionDate Name TotalWeight Ingredient
_Table_ID
-------------- ---- ----------- ----------
1/12/2006 Cement -10 763168138
1/13/2006 Cement -10 763168138
1/13/2006 WhiteCement -10 -1292946867

A Union Query combines all these.

[Q_03 DailyInventoryChanges] SQL:

SELECT [Q_01 Incoming Inventory].PurchaseDate,
[Q_01 Incoming Inventory].TotalWeight,
[Q_01 Incoming Inventory].Ingredient_Table_ID
FROM [Q_01 Incoming Inventory]
UNION ALL
SELECT [Q_02 Outgoing Inventory].ProductionDate,
[Q_02 Outgoing Inventory].TotalWeight,
[Q_02 Outgoing Inventory].Ingredient_Table_ID
FROM [Q_02 Outgoing Inventory]
ORDER BY [Q_01 Incoming Inventory].PurchaseDate,
[Q_01 Incoming Inventory].Ingredient_Table_ID;

Since I don't intend to look at this, I left the raw key values in and
omitted the ingredient names.

[Q_03 DailyInventoryChanges] Query Datasheet View:

PurchaseDate TotalWeight Ingredient_Table_ID
------------ ----------- -------------------
1/12/2006 -10 763168138
1/12/2006 30 763168138
1/13/2006 -10 -1292946867
1/13/2006 20 -1292946867
1/13/2006 -10 763168138
1/13/2006 15 763168138

The next Query adds up the positive and negative changes for each item
during each day. You could, if you wish, revise the Queries to account
for the materials by shift, or by plant name, but I didn't do that here.

[Q_04 Daily Inventory By Ingredient] SQL:

SELECT Ingredient_Table.Name,
[Q_03 DailyInventoryChanges].PurchaseDate,
Sum([Q_03 DailyInventoryChanges].TotalWeight)
AS [Daily Change]
FROM Ingredient_Table
INNER JOIN [Q_03 DailyInventoryChanges]
ON Ingredient_Table.Ingredient_Table_ID
= [Q_03 DailyInventoryChanges].Ingredient_Table_ID
GROUP BY Ingredient_Table.Name,
[Q_03 DailyInventoryChanges].PurchaseDate
ORDER BY Ingredient_Table.Name,
[Q_03 DailyInventoryChanges].PurchaseDate;

Adding up the total changes for each material for each day (among all
plants and including all shifts for that day), we get the following list:

[Q_04 Daily Inventory By Ingredient] Query Datasheet View:

Name PurchaseDate Daily Change
---- ------------ ----- ------
Cement 1/12/2006 20
Cement 1/13/2006 5
WhiteCement 1/13/2006 10

Now, suppose we want to estimate the total amount of material on hand at
any given time. The following Query can do that:

[Q_05 Cumulative Inventory] SQL:

SELECT [Q_04 Daily Inventory By Ingredient].Name,
[Q_04 Daily Inventory By Ingredient].PurchaseDate,
Sum(Q_04A.[Daily Change])
AS [Cumulative Inventory]
FROM [Q_04 Daily Inventory By Ingredient]
INNER JOIN
[Q_04 Daily Inventory By Ingredient] AS Q_04A
ON [Q_04 Daily Inventory By Ingredient].Name
= Q_04A.Name
WHERE (((Q_04A.PurchaseDate)
<=[Q_04 Daily Inventory By Ingredient]
![PurchaseDate]))
GROUP BY [Q_04 Daily Inventory By Ingredient].Name,
[Q_04 Daily Inventory By Ingredient].PurchaseDate
ORDER BY [Q_04 Daily Inventory By Ingredient].Name,
[Q_04 Daily Inventory By Ingredient].PurchaseDate;

.... with the following results, showing a running balance:

[Q_05 Cumulative Inventory] Query Datasheet View:

Name PurchaseDate Cumulative
Inventory
---- ------------ ----------
Cement 1/12/2006 20
Cement 1/13/2006 25
WhiteCement 1/13/2006 10

I should warn you here that my copy of Access gave me some (spurious)
error messages, such as "Query Too Complex", but since it also worked
properly at times, I assume it was just a problem with my copy and I
hope that you will have no trouble using it. If you DO have trouble,
you could try converting some of the Queries to Make-Table Queries, use
them to construct temporary Tables, and base the subsequent Queries on
those Tables, but that's a lot of hassle if you don't need to do it. So
I suggest trying to run Queries similar to mine unless they give you
problems.

HTH.

-- Vincent Johns <[email protected]>
Please feel free to quote anything I say here.
 
Thanks for your reply, while I go through and digest what both of you have
responded with, I have to back up to my ing1 through ing4 fields. My
production manager uses my production FORM to input the daily production of
two different plants. on part of the form he has to input the mix design used
to make a certain block. a mix design would consist of 3 to 4 different
ingredients eg. cement, sand, stone, and slag. I have a table wich has all
the possible ingredients and on the form there is a combo box that he uses.
when he chooses an ingredient it automatically populates a default value for
weight and pulls a cost value from a query that stores the latest cost for
that particular ingredient. From what both have stated a concern about having
ing1 ing2 ing3 and ing4 is this something I should revamp before going on to
creating this report. The manager has to see all ingredients on his form
when he types them in. if they all have the same field name would he not just
be overwriting each ingredient and end up with only one ingredient on that
days production. Thank you for your help.

Bart

Vincent Johns said:
Not knowing what you have in your fields, I had to kind of guess, but
something that jumped out at me was the occurrence of both [IngName1]
and [IngName4] in the same record.

[production] Table fields, including some apparently repeating groups:

ProductionDate
PlantNo
ShiftNO
IngName1
IngName2
IngName3
IngName4
IngWeight1
IngWeight2
IngWeight3
IngWeight4

From what you said, my guess is that they both contain the same kind of
stuff. So, I moved them and the [IngWeight...] fields to a separate
Table, as I illustrate below.

I also made some other changes, such as moving the names of materials to
a Table where they are listed just once, and other Tables make reference
to them via a linking key.

Incidentally, you never mentioned units of measure, so for simplicity I
just assumed they were all in kilograms (or tonnes, or ounces) and
omitted that part. If you DO have any different units, what I show here
won't work, and you'll have to convert all of them to compatible units
to do the arithmetic.

OK, first Table is a stripped-down version of your [Production] Table,
omitting all the repeating groups.

[Production] Table Datasheet View:

Production_ID PlantNo ProductionDate ShiftNO
------------- ------- -------------- -------
-2106329789 A 1/12/2006 1
346130729 A 1/13/2006 1
1585204936 A 1/12/2006 2

As I mentioned, I also put the ingredient names into a Table in which
each is mentioned only once. Other Tables needing to refer to "Cement"
use the key number 763168138 instead of the name "Cement"; this avoids
problems arising from misspelling it as "Cemnet" and not noticing the
mistake until after some wrong totals have been reported. Misspelling
the key number will likely cause an instant error message. (But I don't
expect that you will ever see or use the key numbers directly; the Combo
Boxes or other controls will display only the names.)

[Ingredient_Table] Table Datasheet View:

Ingredient_Table_ID Name
------------------- ----
-1292946867 WhiteCement
763168138 Cement

I created a new Table to list all the materials used during any shift
appearing in the [Production] Table. Its contents might look like this:

[Ingredients Used] Table Datasheet View:

Production_ID Ingredient_Table_ID IngWeight
------------- ------------------- ---------
-2106329789 763168138 3
346130729 -1292946867 10
346130729 763168138 10
1585204936 763168138 7

However, as I said, the key values aren't for human beings to look at,
so I defined a Lookup Query to display, instead of these meaningless
[Production_ID] values, a more usable name for each linked record in the
[Production] Table. This Lookup Query I defined thus:

[QL_Production] SQL:

SELECT Production.Production_ID,
[Production]![PlantNo] & " "
& [Production]![ProductionDate]
& "-" & [Production]![ShiftNO] AS Name
FROM Production
ORDER BY Production.PlantNo, Production.ProductionDate,
Production.ShiftNO;

The displayed names look like this, with the plant name ("A") followed
by date and shift. You could, of course, define this differently, to
display any meaningful name that both is short and uniquely identifies a
record in the [Production] Table.

[QL_Production] Query Datasheet View:

Production_ID Name
------------- --------------
-2106329789 A 1/12/2006-1
1585204936 A 1/12/2006-2
346130729 A 1/13/2006-1

To apply a lookup property to a foreign-key field, open the Table in
Table Design View, select the foreign key, select Lookup, and set the
properties as follows:
Display Control = List Box
Row Source = QL_Production
Column Count = 2
Column Widths = 0;1

I also applied a Lookup propery to the foreign key
[Ingredient_Table_ID], but in that case I looked up the name directly
from the [Ingredient_Table] Table. (Same as above, but set Row Source =
Ingredient_Table .)

With Lookup properties set on the foreign keys, the Table is much more
legible:

[Ingredients Used] Table Datasheet View:

Production_ID Ingredient_Table_ID IngWeight
------------- ------------------- ---------
A 1/12/2006-1 Cement 3
A 1/13/2006-1 WhiteCement 10
A 1/13/2006-1 Cement 10
A 1/12/2006-2 Cement 7

Warning: Some people dislike using Lookup properties because they hide
the fact that the fields actually contain the key numbers, not the names
that show up on the datasheet. So if that bothers you, don't use the
Lookup property. But I shall use them for all the foreign keys in my
examples here, such as in the following Table, showing materials
received into inventory. ([Ingredient_Table_ID] is a foreign key
referring to [Ingredient_Table], and I use a Lookup property here.)

[Incoming_Inventory] Table Datasheet View:

Incoming_ PurchaseDate Ingredient_ IngWeight
Inventory_ID Table_ID
--------- ------------ ----------- ---------
-1602432313 1/13/2006 WhiteCement 20
-1167407823 1/12/2006 Cement 30
-919687266 1/13/2006 Cement 15

Having moved the repeating groups out of the [Production] Table, the
Queries to track the changes to inventory for each type of material are
fairly simple. (OK, they appear a bit lengthy here, but just imagine
how spaghetti-like they'd be if you had to include special code for each
of the 4 "IngName/IngWeight" groups in the original Table! It would be
way more difficult to understand.)

First Query in this list grabs date, material, and weight from the
[Incoming_Inventory] Table. The key value, [Ingredient_Table_ID],
probably isn't needed, since I assume the material names are unique, but
it doesn't hurt anything to leave it in here. You don't need to look at
it. (If you do decide to remove it, you'll have to revise the later
Queries that depend on it.)

[Q_01 Incoming Inventory] SQL:

SELECT Incoming_Inventory.PurchaseDate,
Ingredient_Table.Name,
Sum(Incoming_Inventory.IngWeight) AS TotalWeight,
Ingredient_Table.Ingredient_Table_ID
FROM Ingredient_Table INNER JOIN Incoming_Inventory
ON Ingredient_Table.Ingredient_Table_ID
= Incoming_Inventory.Ingredient_Table_ID
GROUP BY Incoming_Inventory.PurchaseDate,
Ingredient_Table.Name,
Ingredient_Table.Ingredient_Table_ID;

So now we have a list of additions to inventory.

[Q_01 Incoming Inventory] Query Datasheet View:

PurchaseDate Name TotalWeight Ingredient_Table_ID
------------ ---- ----------- -------------------
1/12/2006 Cement 30 763168138
1/13/2006 Cement 15 763168138
1/13/2006 WhiteCement 20 -1292946867

We do the same for deductions from inventory, BUT I attached a minus
sign to them so that I could easily calculate totals.

[Q_02 Outgoing Inventory] SQL:

SELECT Production.ProductionDate,
Ingredient_Table.Name,
Sum(-[IngWeight]) AS TotalWeight,
Ingredient_Table.Ingredient_Table_ID
FROM Production INNER JOIN
(Ingredient_Table INNER JOIN [Ingredients Used]
ON Ingredient_Table.Ingredient_Table_ID
= [Ingredients Used].Ingredient_Table_ID)
ON Production.Production_ID
= [Ingredients Used].Production_ID
GROUP BY Production.ProductionDate,
Ingredient_Table.Name,
Ingredient_Table.Ingredient_Table_ID
ORDER BY Production.ProductionDate;

These fields are similar to those in the previous Query. (There's a
reason for making them match -- I want to combine all of them using a
Union Query.) The minus signs indicate that these values act to reduce
the inventory, instead of increasing it.

[Q_02 Outgoing Inventory] Query Datasheet View:

ProductionDate Name TotalWeight Ingredient
_Table_ID
-------------- ---- ----------- ----------
1/12/2006 Cement -10 763168138
1/13/2006 Cement -10 763168138
1/13/2006 WhiteCement -10 -1292946867

A Union Query combines all these.

[Q_03 DailyInventoryChanges] SQL:

SELECT [Q_01 Incoming Inventory].PurchaseDate,
[Q_01 Incoming Inventory].TotalWeight,
[Q_01 Incoming Inventory].Ingredient_Table_ID
FROM [Q_01 Incoming Inventory]
UNION ALL
SELECT [Q_02 Outgoing Inventory].ProductionDate,
[Q_02 Outgoing Inventory].TotalWeight,
[Q_02 Outgoing Inventory].Ingredient_Table_ID
FROM [Q_02 Outgoing Inventory]
ORDER BY [Q_01 Incoming Inventory].PurchaseDate,
[Q_01 Incoming Inventory].Ingredient_Table_ID;

Since I don't intend to look at this, I left the raw key values in and
omitted the ingredient names.

[Q_03 DailyInventoryChanges] Query Datasheet View:

PurchaseDate TotalWeight Ingredient_Table_ID
------------ ----------- -------------------
1/12/2006 -10 763168138
1/12/2006 30 763168138
1/13/2006 -10 -1292946867
1/13/2006 20 -1292946867
1/13/2006 -10 763168138
1/13/2006 15 763168138

The next Query adds up the positive and negative changes for each item
during each day. You could, if you wish, revise the Queries to account
for the materials by shift, or by plant name, but I didn't do that here.

[Q_04 Daily Inventory By Ingredient] SQL:

SELECT Ingredient_Table.Name,
[Q_03 DailyInventoryChanges].PurchaseDate,
Sum([Q_03 DailyInventoryChanges].TotalWeight)
AS [Daily Change]
FROM Ingredient_Table
INNER JOIN [Q_03 DailyInventoryChanges]
ON Ingredient_Table.Ingredient_Table_ID
= [Q_03 DailyInventoryChanges].Ingredient_Table_ID
GROUP BY Ingredient_Table.Name,
[Q_03 DailyInventoryChanges].PurchaseDate
ORDER BY Ingredient_Table.Name,
[Q_03 DailyInventoryChanges].PurchaseDate;

Adding up the total changes for each material for each day (among all
plants and including all shifts for that day), we get the following list:

[Q_04 Daily Inventory By Ingredient] Query Datasheet View:

Name PurchaseDate Daily Change
---- ------------ ----- ------
Cement 1/12/2006 20
Cement 1/13/2006 5
WhiteCement 1/13/2006 10

Now, suppose we want to estimate the total amount of material on hand at
any given time. The following Query can do that:

[Q_05 Cumulative Inventory] SQL:

SELECT [Q_04 Daily Inventory By Ingredient].Name,
[Q_04 Daily Inventory By Ingredient].PurchaseDate,
Sum(Q_04A.[Daily Change])
AS [Cumulative Inventory]
FROM [Q_04 Daily Inventory By Ingredient]
INNER JOIN
[Q_04 Daily Inventory By Ingredient] AS Q_04A
ON [Q_04 Daily Inventory By Ingredient].Name
= Q_04A.Name
WHERE (((Q_04A.PurchaseDate)
<=[Q_04 Daily Inventory By Ingredient]
![PurchaseDate]))
GROUP BY [Q_04 Daily Inventory By Ingredient].Name,
[Q_04 Daily Inventory By Ingredient].PurchaseDate
ORDER BY [Q_04 Daily Inventory By Ingredient].Name,
[Q_04 Daily Inventory By Ingredient].PurchaseDate;

.... with the following results, showing a running balance:

[Q_05 Cumulative Inventory] Query Datasheet View:

Name PurchaseDate Cumulative
Inventory
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In John Vincent's design you'd have a subform that would allow the entry
of the ingredients/weights. The RecordSource for this subform would be
the [Ingredients Used] table.

You could also have a ListBox that would show all the available
ingredients. This would involve more programming (getting the
ingredients selected & performing the necessary calculations, then
saving the values to the ingredients used table).

His idea of further factoring the data model to have 3 tables, instead
of my 2 tables, is a better idea than mine.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQ81sV4echKqOuFEgEQIASQCfZeTtDtABEd1LR9v8ikk74Yk3jZYAoOJr
LVlK4id2bKyglTreGz89qOfh
=gLjQ
-----END PGP SIGNATURE-----
Thanks for your reply, while I go through and digest what both of you have
responded with, I have to back up to my ing1 through ing4 fields. My
production manager uses my production FORM to input the daily production of
two different plants. on part of the form he has to input the mix design used
to make a certain block. a mix design would consist of 3 to 4 different
ingredients eg. cement, sand, stone, and slag. I have a table wich has all
the possible ingredients and on the form there is a combo box that he uses.
when he chooses an ingredient it automatically populates a default value for
weight and pulls a cost value from a query that stores the latest cost for
that particular ingredient. From what both have stated a concern about having
ing1 ing2 ing3 and ing4 is this something I should revamp before going on to
creating this report. The manager has to see all ingredients on his form
when he types them in. if they all have the same field name would he not just
be overwriting each ingredient and end up with only one ingredient on that
days production. Thank you for your help.

Bart

:

Not knowing what you have in your fields, I had to kind of guess, but
something that jumped out at me was the occurrence of both [IngName1]
and [IngName4] in the same record.

[production] Table fields, including some apparently repeating groups:

ProductionDate
PlantNo
ShiftNO
IngName1
IngName2
IngName3
IngName4
IngWeight1
IngWeight2
IngWeight3
IngWeight4

From what you said, my guess is that they both contain the same kind of
stuff. So, I moved them and the [IngWeight...] fields to a separate
Table, as I illustrate below.

I also made some other changes, such as moving the names of materials to
a Table where they are listed just once, and other Tables make reference
to them via a linking key.

Incidentally, you never mentioned units of measure, so for simplicity I
just assumed they were all in kilograms (or tonnes, or ounces) and
omitted that part. If you DO have any different units, what I show here
won't work, and you'll have to convert all of them to compatible units
to do the arithmetic.

OK, first Table is a stripped-down version of your [Production] Table,
omitting all the repeating groups.

[Production] Table Datasheet View:

Production_ID PlantNo ProductionDate ShiftNO
------------- ------- -------------- -------
-2106329789 A 1/12/2006 1
346130729 A 1/13/2006 1
1585204936 A 1/12/2006 2

As I mentioned, I also put the ingredient names into a Table in which
each is mentioned only once. Other Tables needing to refer to "Cement"
use the key number 763168138 instead of the name "Cement"; this avoids
problems arising from misspelling it as "Cemnet" and not noticing the
mistake until after some wrong totals have been reported. Misspelling
the key number will likely cause an instant error message. (But I don't
expect that you will ever see or use the key numbers directly; the Combo
Boxes or other controls will display only the names.)

[Ingredient_Table] Table Datasheet View:

Ingredient_Table_ID Name
------------------- ----
-1292946867 WhiteCement
763168138 Cement

I created a new Table to list all the materials used during any shift
appearing in the [Production] Table. Its contents might look like this:

[Ingredients Used] Table Datasheet View:

Production_ID Ingredient_Table_ID IngWeight
------------- ------------------- ---------
-2106329789 763168138 3
346130729 -1292946867 10
346130729 763168138 10
1585204936 763168138 7

However, as I said, the key values aren't for human beings to look at,
so I defined a Lookup Query to display, instead of these meaningless
[Production_ID] values, a more usable name for each linked record in the
[Production] Table. This Lookup Query I defined thus:

[QL_Production] SQL:

SELECT Production.Production_ID,
[Production]![PlantNo] & " "
& [Production]![ProductionDate]
& "-" & [Production]![ShiftNO] AS Name
FROM Production
ORDER BY Production.PlantNo, Production.ProductionDate,
Production.ShiftNO;

The displayed names look like this, with the plant name ("A") followed
by date and shift. You could, of course, define this differently, to
display any meaningful name that both is short and uniquely identifies a
record in the [Production] Table.

[QL_Production] Query Datasheet View:

Production_ID Name
------------- --------------
-2106329789 A 1/12/2006-1
1585204936 A 1/12/2006-2
346130729 A 1/13/2006-1

To apply a lookup property to a foreign-key field, open the Table in
Table Design View, select the foreign key, select Lookup, and set the
properties as follows:
Display Control = List Box
Row Source = QL_Production
Column Count = 2
Column Widths = 0;1

I also applied a Lookup propery to the foreign key
[Ingredient_Table_ID], but in that case I looked up the name directly
from the [Ingredient_Table] Table. (Same as above, but set Row Source =
Ingredient_Table .)

With Lookup properties set on the foreign keys, the Table is much more
legible:

[Ingredients Used] Table Datasheet View:

Production_ID Ingredient_Table_ID IngWeight
------------- ------------------- ---------
A 1/12/2006-1 Cement 3
A 1/13/2006-1 WhiteCement 10
A 1/13/2006-1 Cement 10
A 1/12/2006-2 Cement 7

Warning: Some people dislike using Lookup properties because they hide
the fact that the fields actually contain the key numbers, not the names
that show up on the datasheet. So if that bothers you, don't use the
Lookup property. But I shall use them for all the foreign keys in my
examples here, such as in the following Table, showing materials
received into inventory. ([Ingredient_Table_ID] is a foreign key
referring to [Ingredient_Table], and I use a Lookup property here.)

[Incoming_Inventory] Table Datasheet View:

Incoming_ PurchaseDate Ingredient_ IngWeight
Inventory_ID Table_ID
--------- ------------ ----------- ---------
-1602432313 1/13/2006 WhiteCement 20
-1167407823 1/12/2006 Cement 30
-919687266 1/13/2006 Cement 15

Having moved the repeating groups out of the [Production] Table, the
Queries to track the changes to inventory for each type of material are
fairly simple. (OK, they appear a bit lengthy here, but just imagine
how spaghetti-like they'd be if you had to include special code for each
of the 4 "IngName/IngWeight" groups in the original Table! It would be
way more difficult to understand.)

First Query in this list grabs date, material, and weight from the
[Incoming_Inventory] Table. The key value, [Ingredient_Table_ID],
probably isn't needed, since I assume the material names are unique, but
it doesn't hurt anything to leave it in here. You don't need to look at
it. (If you do decide to remove it, you'll have to revise the later
Queries that depend on it.)

[Q_01 Incoming Inventory] SQL:

SELECT Incoming_Inventory.PurchaseDate,
Ingredient_Table.Name,
Sum(Incoming_Inventory.IngWeight) AS TotalWeight,
Ingredient_Table.Ingredient_Table_ID
FROM Ingredient_Table INNER JOIN Incoming_Inventory
ON Ingredient_Table.Ingredient_Table_ID
= Incoming_Inventory.Ingredient_Table_ID
GROUP BY Incoming_Inventory.PurchaseDate,
Ingredient_Table.Name,
Ingredient_Table.Ingredient_Table_ID;

So now we have a list of additions to inventory.

[Q_01 Incoming Inventory] Query Datasheet View:

PurchaseDate Name TotalWeight Ingredient_Table_ID
------------ ---- ----------- -------------------
1/12/2006 Cement 30 763168138
1/13/2006 Cement 15 763168138
1/13/2006 WhiteCement 20 -1292946867

We do the same for deductions from inventory, BUT I attached a minus
sign to them so that I could easily calculate totals.

[Q_02 Outgoing Inventory] SQL:

SELECT Production.ProductionDate,
Ingredient_Table.Name,
Sum(-[IngWeight]) AS TotalWeight,
Ingredient_Table.Ingredient_Table_ID
FROM Production INNER JOIN
(Ingredient_Table INNER JOIN [Ingredients Used]
ON Ingredient_Table.Ingredient_Table_ID
= [Ingredients Used].Ingredient_Table_ID)
ON Production.Production_ID
= [Ingredients Used].Production_ID
GROUP BY Production.ProductionDate,
Ingredient_Table.Name,
Ingredient_Table.Ingredient_Table_ID
ORDER BY Production.ProductionDate;

These fields are similar to those in the previous Query. (There's a
reason for making them match -- I want to combine all of them using a
Union Query.) The minus signs indicate that these values act to reduce
the inventory, instead of increasing it.

[Q_02 Outgoing Inventory] Query Datasheet View:

ProductionDate Name TotalWeight Ingredient
_Table_ID
-------------- ---- ----------- ----------
1/12/2006 Cement -10 763168138
1/13/2006 Cement -10 763168138
1/13/2006 WhiteCement -10 -1292946867

A Union Query combines all these.

[Q_03 DailyInventoryChanges] SQL:

SELECT [Q_01 Incoming Inventory].PurchaseDate,
[Q_01 Incoming Inventory].TotalWeight,
[Q_01 Incoming Inventory].Ingredient_Table_ID
FROM [Q_01 Incoming Inventory]
UNION ALL
SELECT [Q_02 Outgoing Inventory].ProductionDate,
[Q_02 Outgoing Inventory].TotalWeight,
[Q_02 Outgoing Inventory].Ingredient_Table_ID
FROM [Q_02 Outgoing Inventory]
ORDER BY [Q_01 Incoming Inventory].PurchaseDate,
[Q_01 Incoming Inventory].Ingredient_Table_ID;

Since I don't intend to look at this, I left the raw key values in and
omitted the ingredient names.

[Q_03 DailyInventoryChanges] Query Datasheet View:

PurchaseDate TotalWeight Ingredient_Table_ID
------------ ----------- -------------------
1/12/2006 -10 763168138
1/12/2006 30 763168138
1/13/2006 -10 -1292946867
1/13/2006 20 -1292946867
1/13/2006 -10 763168138
1/13/2006 15 763168138

The next Query adds up the positive and negative changes for each item
during each day. You could, if you wish, revise the Queries to account
for the materials by shift, or by plant name, but I didn't do that here.

[Q_04 Daily Inventory By Ingredient] SQL:

SELECT Ingredient_Table.Name,
[Q_03 DailyInventoryChanges].PurchaseDate,
Sum([Q_03 DailyInventoryChanges].TotalWeight)
AS [Daily Change]
FROM Ingredient_Table
INNER JOIN [Q_03 DailyInventoryChanges]
ON Ingredient_Table.Ingredient_Table_ID
= [Q_03 DailyInventoryChanges].Ingredient_Table_ID
GROUP BY Ingredient_Table.Name,
[Q_03 DailyInventoryChanges].PurchaseDate
ORDER BY Ingredient_Table.Name,
[Q_03 DailyInventoryChanges].PurchaseDate;

Adding up the total changes for each material for each day (among all
plants and including all shifts for that day), we get the following list:

[Q_04 Daily Inventory By Ingredient] Query Datasheet View:

Name PurchaseDate Daily Change
---- ------------ ----- ------
Cement 1/12/2006 20
Cement 1/13/2006 5
WhiteCement 1/13/2006 10

Now, suppose we want to estimate the total amount of material on hand at
any given time. The following Query can do that:

[Q_05 Cumulative Inventory] SQL:

SELECT [Q_04 Daily Inventory By Ingredient].Name,
[Q_04 Daily Inventory By Ingredient].PurchaseDate,
Sum(Q_04A.[Daily Change])
AS [Cumulative Inventory]
FROM [Q_04 Daily Inventory By Ingredient]
INNER JOIN
[Q_04 Daily Inventory By Ingredient] AS Q_04A
ON [Q_04 Daily Inventory By Ingredient].Name
= Q_04A.Name
WHERE (((Q_04A.PurchaseDate)
<=[Q_04 Daily Inventory By Ingredient]
![PurchaseDate]))
GROUP BY [Q_04 Daily Inventory By Ingredient].Name,
[Q_04 Daily Inventory By Ingredient].PurchaseDate
ORDER BY [Q_04 Daily Inventory By Ingredient].Name,
[Q_04 Daily Inventory By Ingredient].PurchaseDate;

.... with the following results, showing a running balance:

[Q_05 Cumulative Inventory] Query Datasheet View:

Name PurchaseDate Cumulative
Inventory
 
thanks For your help both of you.. I ran all the querys and did not get an
error This would work fine.. I now have to adapt it to my program some how
to make this work for now. We are using this data base Begining 2006. I.ll
have to re write a lot of the data base to make it work your way .. I have a
form with an imbedded form that we input the employees that worked and their
hours workd for the day. This works similar to how you have told me to do
the ingredient. so I will be able to adapt the material cost data to my
employee cost data also. thanks for all your help without the help I get here
it would not have been possible to have a database like this.

--
Bart


MGFoster said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In John Vincent's design you'd have a subform that would allow the entry
of the ingredients/weights. The RecordSource for this subform would be
the [Ingredients Used] table.

You could also have a ListBox that would show all the available
ingredients. This would involve more programming (getting the
ingredients selected & performing the necessary calculations, then
saving the values to the ingredients used table).

His idea of further factoring the data model to have 3 tables, instead
of my 2 tables, is a better idea than mine.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQ81sV4echKqOuFEgEQIASQCfZeTtDtABEd1LR9v8ikk74Yk3jZYAoOJr
LVlK4id2bKyglTreGz89qOfh
=gLjQ
-----END PGP SIGNATURE-----
Thanks for your reply, while I go through and digest what both of you have
responded with, I have to back up to my ing1 through ing4 fields. My
production manager uses my production FORM to input the daily production of
two different plants. on part of the form he has to input the mix design used
to make a certain block. a mix design would consist of 3 to 4 different
ingredients eg. cement, sand, stone, and slag. I have a table wich has all
the possible ingredients and on the form there is a combo box that he uses.
when he chooses an ingredient it automatically populates a default value for
weight and pulls a cost value from a query that stores the latest cost for
that particular ingredient. From what both have stated a concern about having
ing1 ing2 ing3 and ing4 is this something I should revamp before going on to
creating this report. The manager has to see all ingredients on his form
when he types them in. if they all have the same field name would he not just
be overwriting each ingredient and end up with only one ingredient on that
days production. Thank you for your help.

Bart

:

Not knowing what you have in your fields, I had to kind of guess, but
something that jumped out at me was the occurrence of both [IngName1]
and [IngName4] in the same record.

[production] Table fields, including some apparently repeating groups:

ProductionDate
PlantNo
ShiftNO
IngName1
IngName2
IngName3
IngName4
IngWeight1
IngWeight2
IngWeight3
IngWeight4

From what you said, my guess is that they both contain the same kind of
stuff. So, I moved them and the [IngWeight...] fields to a separate
Table, as I illustrate below.

I also made some other changes, such as moving the names of materials to
a Table where they are listed just once, and other Tables make reference
to them via a linking key.

Incidentally, you never mentioned units of measure, so for simplicity I
just assumed they were all in kilograms (or tonnes, or ounces) and
omitted that part. If you DO have any different units, what I show here
won't work, and you'll have to convert all of them to compatible units
to do the arithmetic.

OK, first Table is a stripped-down version of your [Production] Table,
omitting all the repeating groups.

[Production] Table Datasheet View:

Production_ID PlantNo ProductionDate ShiftNO
------------- ------- -------------- -------
-2106329789 A 1/12/2006 1
346130729 A 1/13/2006 1
1585204936 A 1/12/2006 2

As I mentioned, I also put the ingredient names into a Table in which
each is mentioned only once. Other Tables needing to refer to "Cement"
use the key number 763168138 instead of the name "Cement"; this avoids
problems arising from misspelling it as "Cemnet" and not noticing the
mistake until after some wrong totals have been reported. Misspelling
the key number will likely cause an instant error message. (But I don't
expect that you will ever see or use the key numbers directly; the Combo
Boxes or other controls will display only the names.)

[Ingredient_Table] Table Datasheet View:

Ingredient_Table_ID Name
------------------- ----
-1292946867 WhiteCement
763168138 Cement

I created a new Table to list all the materials used during any shift
appearing in the [Production] Table. Its contents might look like this:

[Ingredients Used] Table Datasheet View:

Production_ID Ingredient_Table_ID IngWeight
------------- ------------------- ---------
-2106329789 763168138 3
346130729 -1292946867 10
346130729 763168138 10
1585204936 763168138 7

However, as I said, the key values aren't for human beings to look at,
so I defined a Lookup Query to display, instead of these meaningless
[Production_ID] values, a more usable name for each linked record in the
[Production] Table. This Lookup Query I defined thus:

[QL_Production] SQL:

SELECT Production.Production_ID,
[Production]![PlantNo] & " "
& [Production]![ProductionDate]
& "-" & [Production]![ShiftNO] AS Name
FROM Production
ORDER BY Production.PlantNo, Production.ProductionDate,
Production.ShiftNO;

The displayed names look like this, with the plant name ("A") followed
by date and shift. You could, of course, define this differently, to
display any meaningful name that both is short and uniquely identifies a
record in the [Production] Table.

[QL_Production] Query Datasheet View:

Production_ID Name
------------- --------------
-2106329789 A 1/12/2006-1
1585204936 A 1/12/2006-2
346130729 A 1/13/2006-1

To apply a lookup property to a foreign-key field, open the Table in
Table Design View, select the foreign key, select Lookup, and set the
properties as follows:
Display Control = List Box
Row Source = QL_Production
Column Count = 2
Column Widths = 0;1

I also applied a Lookup propery to the foreign key
[Ingredient_Table_ID], but in that case I looked up the name directly
from the [Ingredient_Table] Table. (Same as above, but set Row Source =
Ingredient_Table .)

With Lookup properties set on the foreign keys, the Table is much more
legible:

[Ingredients Used] Table Datasheet View:

Production_ID Ingredient_Table_ID IngWeight
------------- ------------------- ---------
A 1/12/2006-1 Cement 3
A 1/13/2006-1 WhiteCement 10
A 1/13/2006-1 Cement 10
A 1/12/2006-2 Cement 7

Warning: Some people dislike using Lookup properties because they hide
the fact that the fields actually contain the key numbers, not the names
that show up on the datasheet. So if that bothers you, don't use the
Lookup property. But I shall use them for all the foreign keys in my
examples here, such as in the following Table, showing materials
received into inventory. ([Ingredient_Table_ID] is a foreign key
referring to [Ingredient_Table], and I use a Lookup property here.)

[Incoming_Inventory] Table Datasheet View:

Incoming_ PurchaseDate Ingredient_ IngWeight
Inventory_ID Table_ID
--------- ------------ ----------- ---------
-1602432313 1/13/2006 WhiteCement 20
-1167407823 1/12/2006 Cement 30
-919687266 1/13/2006 Cement 15

Having moved the repeating groups out of the [Production] Table, the
Queries to track the changes to inventory for each type of material are
fairly simple. (OK, they appear a bit lengthy here, but just imagine
how spaghetti-like they'd be if you had to include special code for each
of the 4 "IngName/IngWeight" groups in the original Table! It would be
way more difficult to understand.)

First Query in this list grabs date, material, and weight from the
[Incoming_Inventory] Table. The key value, [Ingredient_Table_ID],
probably isn't needed, since I assume the material names are unique, but
it doesn't hurt anything to leave it in here. You don't need to look at
it. (If you do decide to remove it, you'll have to revise the later
Queries that depend on it.)

[Q_01 Incoming Inventory] SQL:

SELECT Incoming_Inventory.PurchaseDate,
Ingredient_Table.Name,
Sum(Incoming_Inventory.IngWeight) AS TotalWeight,
Ingredient_Table.Ingredient_Table_ID
FROM Ingredient_Table INNER JOIN Incoming_Inventory
ON Ingredient_Table.Ingredient_Table_ID
= Incoming_Inventory.Ingredient_Table_ID
GROUP BY Incoming_Inventory.PurchaseDate,
Ingredient_Table.Name,
Ingredient_Table.Ingredient_Table_ID;

So now we have a list of additions to inventory.

[Q_01 Incoming Inventory] Query Datasheet View:

PurchaseDate Name TotalWeight Ingredient_Table_ID
------------ ---- ----------- -------------------
1/12/2006 Cement 30 763168138
1/13/2006 Cement 15 763168138
1/13/2006 WhiteCement 20 -1292946867

We do the same for deductions from inventory, BUT I attached a minus
sign to them so that I could easily calculate totals.

[Q_02 Outgoing Inventory] SQL:

SELECT Production.ProductionDate,
Ingredient_Table.Name,
Sum(-[IngWeight]) AS TotalWeight,
Ingredient_Table.Ingredient_Table_ID
FROM Production INNER JOIN
(Ingredient_Table INNER JOIN [Ingredients Used]
ON Ingredient_Table.Ingredient_Table_ID
= [Ingredients Used].Ingredient_Table_ID)
ON Production.Production_ID
= [Ingredients Used].Production_ID
GROUP BY Production.ProductionDate,
Ingredient_Table.Name,
Ingredient_Table.Ingredient_Table_ID
ORDER BY Production.ProductionDate;

These fields are similar to those in the previous Query. (There's a
reason for making them match -- I want to combine all of them using a
Union Query.) The minus signs indicate that these values act to reduce
the inventory, instead of increasing it.

[Q_02 Outgoing Inventory] Query Datasheet View:

ProductionDate Name TotalWeight Ingredient
_Table_ID
-------------- ---- ----------- ----------
1/12/2006 Cement -10 763168138
1/13/2006 Cement -10 763168138
1/13/2006 WhiteCement -10 -1292946867

A Union Query combines all these.

[Q_03 DailyInventoryChanges] SQL:

SELECT [Q_01 Incoming Inventory].PurchaseDate,
[Q_01 Incoming Inventory].TotalWeight,
[Q_01 Incoming Inventory].Ingredient_Table_ID
FROM [Q_01 Incoming Inventory]
UNION ALL
SELECT [Q_02 Outgoing Inventory].ProductionDate,
[Q_02 Outgoing Inventory].TotalWeight,
[Q_02 Outgoing Inventory].Ingredient_Table_ID
FROM [Q_02 Outgoing Inventory]
ORDER BY [Q_01 Incoming Inventory].PurchaseDate,
[Q_01 Incoming Inventory].Ingredient_Table_ID;

Since I don't intend to look at this, I left the raw key values in and
omitted the ingredient names.

[Q_03 DailyInventoryChanges] Query Datasheet View:

PurchaseDate TotalWeight Ingredient_Table_ID
------------ ----------- -------------------
1/12/2006 -10 763168138
1/12/2006 30 763168138
1/13/2006 -10 -1292946867
1/13/2006 20 -1292946867
1/13/2006 -10 763168138
1/13/2006 15 763168138

The next Query adds up the positive and negative changes for each item
during each day. You could, if you wish, revise the Queries to account
for the materials by shift, or by plant name, but I didn't do that here.

[Q_04 Daily Inventory By Ingredient] SQL:

SELECT Ingredient_Table.Name,
[Q_03 DailyInventoryChanges].PurchaseDate,
Sum([Q_03 DailyInventoryChanges].TotalWeight)
 
I don't exactly want to suggest that you do extra work, but maybe this
could simplify some things for you, so here goes...

Since you mentioned "the employees that worked and their hours worked
for the day," I immediately began wondering if you'd looked at the "Time
and Billing" template in the Database Wizard. (You can find that via
File --> New, the Databases tab.)

The "Time and Billing" database contains a [Time Cards] Form that you
might find it useful to adapt. If each employee always works only on
one project, perhaps it's a bit fancier than what you need, but you
might at least look at it as an example of what you might want to do, if
not now, then perhaps later on. Labor costs are a major part of your
expenses, and if you can apply them more precisely to projects (without
unduly annoying the people who are trying to get the work done), you
have more insight into how you ought to do your billing on future
projects according to your experiences with past ones. (Or, more
directly, if you can bill for time & materials, you now know more
precisely how much time was actually involved.)

My suggestion is to load the "Time and Billing" database and play around
with it. Since the Tables are unpopulated, you'll have to enter dummy
data yourself as you do that. You can examine the Relationships (there
are many), the design of fields in the Tables, etc. Sadly, it's a bit
skimpy on the "Descriptions" of fields in the Tables, but you should
easily be able to guess what they mean. My own inclination is to
include lots of Descriptions, including example values.

If you don't like the database, you can delete it without doing any
harm. Or you can copy Tables, Forms, &c., to your own database, rename
the components to match the ones you're using, and save yourself some
work. (You can even copy field definitions from one Table to another,
in Table Design View, via the Copy and Paste operations in Access.)

-- Vincent Johns <[email protected]>
Please feel free to quote anything I say here.
 
Back
Top