Action Query vs Form Code

S

SENTRY 1

Multi Level Inventory Item. One change to a single Inventory item could
require changes to all other Inventory items that use that Item In order to
update all other Inventory items, I have created a form that the "On
Current" event will run code which will check and modify all areas of that
item. Problem is that you have to move from record to record to cause the
"On Current" Event to trigger. This doesn't sound like an intelligent
programming method. Is there a way to run code through an Action Query or
should I open my Form and automatically move from record to record to
initiate the "On Current" event. (If so how do I do This?). Thanks in
advance.
 
L

Larry Daugherty

If you are using Access with Jet as the RDBMS and a change in one item
requires a change in other items (whether at the same or higher or
lower data levels), as you've stated it, then your schema/data design
is thoroughly broken. Or it could be that you are changing a
component of the primary key of a parent record and haven't set
Referential Integrity in the Relationships. If you are using SQL
Server, Oracle or some other of the industrial strength back ends you
may need to write an appropriate trigger routine and store it in that
database.

HTH
 
S

SENTRY 1

Thanks for responding "Larry Daugherty"
I am using Access with Jet as the RDBMS
and a change in one item does require a change in other items (whether at
the same or higher or lower data levels), and you might be right my
"schema/data design" may be poorly designed. I hope this explains my
situation better:

My Table "Inventory" consists of Item A, B, C, D, E, F and G. A, B, C, & D
are Base items. E consists of the addition of (1)A & (1)B. F consists of
the addition of (1)C & (2)D's. G consists of the combination of (2)E'S
&(1)F. Therefore, if I change the cost of A, I need to automatically
change the cost of E, and because E is now changed, I must automatically
change the cost of G.

A Second Table, "Assemblies" keeps track of what is combined to what.

After I change any pricing in "Inventory" I open a Form which checks the
Assembly combinations, adds them together and the Total Costs are written
back to "Inventory" (does this through "On Current" as I scroll through the
records).

It sorts the records by level (lowest to highest) so the level 1 are updated
before Level 2 etc

Am I totally up the wrong tree so far? Does this setup make sense? If so,
how can I automatically update the records everytime I adjust a cost without
opening the Form and scrolling through the records to update them?

Thanks in Advance, I've never used this Forum before but I'm stuck.
 
L

Larry Daugherty

You should use the Access newsgroups a lot. Look at them as one more
resource to help you get your work done. I recommend that you lurk
and learn in microsoft.public.access.gettingstarted and
microsoft.public.access.tablesdesign to begin. I recommend that you
visit www.mvps.ort/access and review the "Rules for Databases" of
something named like that. That site is an incredibly valuable
resource to Access developers. Another neat thing to do is to Google
these access groups on your specific issue. You can construct a
Google query to search for your issue across all of the Access groups
in one shot.

Your ideas about the data are more at fault than the data in the first
part. Just forget about fields E,F, and G in that first table. Any
time you need to display or report those derived values, calculate
them. Calculation is the only reliable way to deal with that
situation and requires storing the calculation once as opposed to
storing calculated results for each record. Do not store calculated
results back into the database; at all, ever. Once you understand the
truth of what I have written and you have the appropriate calculations
in place delete those fields from the Inventory table.

Learning the rules about relational database management systems will
lead you to the conclusions above.

The Assemblies part seems to recall a distant echo of "Indented Bill
of Material" chiming.

Your idea of calculating the things you have from the bottom up is
correct. The calculations in use and where you are applying them is
*wrong*

It seems that what you have is the implementation in Access of an
Excel (or other) spreadsheet. Let's change the thinking to
"relational". Some of this will be counter-intuitive. I'll try to
explain how it works at the end... Also, I'll just show some of the
main fields. The ones shown will suffice for a simple system. More
complex considerations may require more fields.

From what you have given, I would characterize what your Inventory
application is tracking as Assemblies and maybe Items. Higher order
assemblies may contain lower order assemblies. In that context, the
lower level assemblies are "sub-assemblies". Lowest level assemblies
contain Items. If your Inventory application is about Finished Goods
then Items don't play. If you're after a complete bill of materials
then Items do play.

First, assume BOM

Table Item will have fields for:
ItemID(Autonumber), ItemName, ItemDescription,
ItemMaterialType, ItemCost, ItemNotes
This is about a single item in raw inventory.

Table Assembly will have fields for:
AssemblyID(Auto...), AssemblyName, AssemblyDescription,
AssemblyNotes
This is about a single assembly.

Table AssemblyItem will have fields for:
AssemblyItemID(Auto...), AssemblyID, ItemID,
AssemblyItemQuantity, AssemblyItemNotes
this is about a single item and the quantity
of it in this assembly

Table AssemblySubAssembly will have fields for:
AssySubAssyItemID{Auto...)
AssemblyID of containing assembly
AssemblyID of sub-assembly, SubAssyQuantity
AssemblySubAssemblyNotes
this is about a single assembly and the quantity
of it in this higher assembly

Note that the above tables don't fully address costs. That's because
I don't know how you arrive at the cost figures you use. I also don't
know if you use different cost figures for in-house transfers versus
sales If you have a separate labor or overhead or other cost that is
included in the assembly cost over and above the cost of the
components then it must be shown as a cost field at that level, call
it AssembleCost. The cost for the whole assembly will be the sum of
AssembleCost and all of the component item costs. Do not store that
sum in the database! Calculate it each time you need it.

Your tables and fields should look either exactly like that or a lot
like that. With the tables and fields as above you're ready to go
with the rest of your design.

You may have noticed that your original number of tables has grown.
That's exactly the way it should be. You may have noticed another
disturbing thing. Some of the tables include the Primary (ID) fields
of other tables. That's part of how the relationships between tables
are communicated. It's just that it kind of seems backwards! A
moment's digression: Access and other relational database management
systems are based on set theory from mathematics. That's where the
"relational" part originates and it's fundamental to the thinking.
There are "parent-child" relationships, in database parlance they are
"one-to-many" relationships. Rather than dealing with the
complexities of trying to contain the names of none to infinite
children within the parent record, each child record simply contains
the Primary Key of the parent record. That handles the case of one to
many. What about those cases of many-to-many; car manufacturers and
car colors for example? In that case you track the Primary Key of
both parents.in each child record. A table for that purpose is called
a "junction table". Using that table you could find all Mercedes of
any color or all red cars from any manufacturer. Depending on the
application, you could find that a significant fraction of records are
of that type. Spend a while with it and it will all make sense.

Once your data is as above you can design your Forms, Queries and
Reports. Post back with questions.

HTH
 
L

Larry Daugherty

A detail... in the foregoing response the primary keys are all
autonumber datatype so the foreign keys (the reference to the parent's
primary key) in the child tables are all Long Integer numbers.
 
S

SENTRY 1

WOW!

It makes sense how you have suggested the different tables, and their
relationship to each other. One problem I'm trying to wrap my head around
is, I will need to have all Items and Assemblies show up together on one Form
for the purpose of selecting them for sales. (I sell individual components
or assemblies or partial assemblies depending on customers needs). For this
form, do I create query and bring them all togeter? It seems I would have Id
number conflicts and sorting problems.
 
L

Larry Daugherty

Hi again.

You've just added a new concept: a partial assembly. I think that it
is really an assembly with optional and selectable subassemblies
and/or Items. Fair enough it you keep the different things straight.
For purposes of discussion, there is a high order assembly the
equivalent of a PC motherboard. That bare bones motherboard has its
own assembly number. You may define other assemblies or SKUs that use
that same assembly with various flavors and degrees of population.
That's where the idea of an indented BOM comes into play in our
discussion. It's just that for everything you want to treat as a
defined entity must, in fact, be defined. :)

It gets complicated because what you are doing is complicated.
However, hanging in there and analyzing your needs and then getting
the schema correct will make it all possible. By addressing one issue
at a time, in the right order, you'll get there.

You've introduced the idea of orders. The Quotes and Orders table
will occupy a place at the top of the hierarchy. A Quote can become
an Order so they should likely be in the same table Lots for you to
get your head around in that area. By implication you will also need
tables for Company, Person, Address, OrderDetail, Shipper?, etc.
There will also have to be Lookup tables (Not Lookup Fields!) for
items that are entered repeatedly. Saves typing and errors and
increases speed.

To see one example of how some of this might play out, open the
Northwinds.mdb that came with Access. It covers a lot of ground.

Everything in the house that can be ordered needs to have a part name
and part number. In addition, the concept of Category has to be
brought into play so that you can rapidly filter out everything in the
database except things in the category of immediate interest. I'm
sure you already have categories in play in your place of business.
Anyway you'll quickly narrow your list from "everything" to just a few
candidate items or the specific item/assembly you want. Click that
one thing to make it the current line item in the quote/order, enter a
quantity and Press On to the next line.

Play with Northwinds and learn a lot. Get into design mode on the
forms to see what's under the hood. Don't worry about the
Switchboards. You don't have to know how they work only how to make
them work for you by following directions.

You'll find that given a correct schema, the queries are relatively
easy.

We've gone a long way in one day from A, B, C, D and E, F, G.

HTH
 
S

SENTRY 1

Larry Daugherty said:
Hi again.

You've just added a new concept: a partial assembly. I think that it
is really an assembly with optional and selectable subassemblies
and/or Items. Fair enough it you keep the different things straight.
For purposes of discussion, there is a high order assembly the
equivalent of a PC motherboard. That bare bones motherboard has its
own assembly number. You may define other assemblies or SKUs that use
that same assembly with various flavors and degrees of population.
That's where the idea of an indented BOM comes into play in our
discussion. It's just that for everything you want to treat as a
defined entity must, in fact, be defined. :)

It gets complicated because what you are doing is complicated.
However, hanging in there and analyzing your needs and then getting
the schema correct will make it all possible. By addressing one issue
at a time, in the right order, you'll get there.

You've introduced the idea of orders. The Quotes and Orders table
will occupy a place at the top of the hierarchy. A Quote can become
an Order so they should likely be in the same table Lots for you to
get your head around in that area. By implication you will also need
tables for Company, Person, Address, OrderDetail, Shipper?, etc.
There will also have to be Lookup tables (Not Lookup Fields!) for
items that are entered repeatedly. Saves typing and errors and
increases speed.

To see one example of how some of this might play out, open the
Northwinds.mdb that came with Access. It covers a lot of ground.

Everything in the house that can be ordered needs to have a part name
and part number. In addition, the concept of Category has to be
brought into play so that you can rapidly filter out everything in the
database except things in the category of immediate interest. I'm
sure you already have categories in play in your place of business.
Anyway you'll quickly narrow your list from "everything" to just a few
candidate items or the specific item/assembly you want. Click that
one thing to make it the current line item in the quote/order, enter a
quantity and Press On to the next line.

Play with Northwinds and learn a lot. Get into design mode on the
forms to see what's under the hood. Don't worry about the
Switchboards. You don't have to know how they work only how to make
them work for you by following directions.

You'll find that given a correct schema, the queries are relatively
easy.

We've gone a long way in one day from A, B, C, D and E, F, G.

HTH
--
-Larry-
--




Sorry, I should let you know, all those other things you've mentioned are already up and running. A little history... I wrote this entire package 5 years ago for my rental business and have been running it ever since. As far as Rentals go it kept track of all equipment, calculated rental, created contracts, Invoices, customer sales, taxes, reports yada yada yada.

Now, that I've sold the rental business, I'm modifing the program for my
manufacturing business. Everything is transferable except the Inventory
modual. Now instead of rental rates, I'm dealing with costs which are
somewhat complex as the items are either sold individually or as part of a
larger item. Though not structured properly, I'm actually using it for day
to day operations. The updates through assembly levels are the problem.

You've suggested some ideas that I've grabbed onto, but I'm not out of the
woods yet.

I have set up the Inventory as you suggested with "Select Category" then
"Select Item". All my items whether asssemblies or not, are in the same
Table. There is a Flag which distinguishes between Assemblies or Base items.
If it is an Assembly you can move to an Assembly Form and add or remove base
items, which in turn, are called from the same Inventory Table. And it
tracks the assembly level (so you can update 1 before 2 etc)

I am able to select items and add them to an Invoice, sell them, decrease
inventory etc.

If I change a Base item, I can update the item where its being used, simply
by going to that item in the Inventory Form. However, like a pyramid, the
task gets larger and larger. What I cannot figure out is how to
automatically update all levels of assemblies. (Although I thoughly
understand the lunicy of storing calculated numbers, I haven't figured any
other way) Part of the problem is that the selling price is based on total
cost and if you don't update the cost, the selling price is wrong at level 1
therefore its wrong at level 2... therefore you cannot print up a pricelist
without updating all of your costs. (have I gone around the circle yet!)

Anyway, I may have to completly rethink my Inventory / BOM methodology. Is
there any examples similar to what I'm trying to accomplish? I hate to
burden you with a million questions while I reinvent the wheel.

Thanks again
 
L

Larry Daugherty

That dual cost structure was what I was alluding to when I mentioned
In-House transfer cost. the relationship between the cost of an item
as an end item and the cost of an item as a component of a higher
assembly is a constant ratio or a j factor plus a constant ratio then
you only need one Cost field per item or assembly. However, if there
is no predictable relationship between the two cost types then two
cost fields will be required. You have to decide what the business
rules are and then define them for purposes of your application. Once
you have decide which way it is then queries can be constructed that
will perform the correct magic for the current operation.

All costs reported must be the result of calculations on the cost
field(s) If you have to make cost entries and changes at anything
above the lowest level then you are running your business by personal
fiat rather than by algorhythmic rules.

You wrote " What I cannot figure out is how to automatically update
all levels of assemblies". That's what I've been getting at above.
If you have an algorithmic method for arriving at the cost of an
assembly then it can be programmed. If you don't then it can't.
Here's what I think should be happening. The cost of an assembly is
the sum of all of the in-house transfer costs of included
subassemblies and items plus the hours and fractions of hours of labor
required to populate the assembly multiplied by the loaded labor rate
and added to the preceding sum. Somewhere the cost for labor and
packing materials to ready for shipment must be added Items,
assemblies and possibly Orders...In-house transfer items tend to be
less costly because little or no packing is required. On the other
hand, there is a labor cost of loading a sub assembly or item into the
next higher assembly. That cost could be determined and added to the
lower item's in-house transfer cost rather than assigning the cost to
the higher level assembly. It has to be calculated or entered at one
level or the other..

Northwinds is useful to explore to see a hierarchy of things playing
together. Notice that their Orders sums item costs..

I have to call it day.my chin is causing typos. :)

HTH
--
-Larry-
--

mentioned are already up and running. A little history... I wrote
this entire package 5 years ago for my rental business and have been
running it ever since. As far as Rentals go it kept track of all
equipment, calculated rental, created contracts, Invoices, customer
sales, taxes, reports yada yada yada.
 
R

redmannn177

How do I have a list of customers and want kind of car they are looking for
and use that and match them up with my inventory list of cars?
 
G

G.A.WANI

I had a problem in MS-Access 2007 for making Reports in more than two groups.
My problem has not been understood by most of the group members. Therefore,
I thought it better to explain it in an example where two groups viz.
Subject and Gender are given. Therefore running serial over each group is
required separately in addition to general serial no. MS-Access 2007
assigns the same S.No. to Boys and Girls group as is being assigned to
subjects group because in MS-Access Running Sum applies to the location for
immediate group. The Report output is required as per table given below:-

Gen. Sub. Gender Name Marks
S.No S.No S.No

Physics Group

Boys Group

1 1 1 A.M. Shah 80
2 2 2 S.A. Khan 90
3 3 3 Ashok Kumar 95
4 4 4 Vidya Bushan 68
5 5 5 M.D. Dhar 69
6 6 6 Salman 70
7 7 7 Pawan Kumar 81
Girls Group
8 8 1 Mirdula 74
9 9 2 Margina 86
10 10 3 Suriya 79
11 11 4 Bindu 37
12 12 5 Anju 84
13 13 6 Tabasum 63
14 14 7 Ritika 98
15 15 8 Sachi 93

Chemistry Group

Boys Group
16 1 1 Vergeese 74
17 2 2 Wahab 78
18 3 3 Rahul 79
Girls Group
19 4 1 Christina 70
20 5 2 Faheeda 72
21 6 3 Maria 76
22 7 4 Sumbal 77
In this case I think MS-Access 2007 has limitations if there is no solution
to this problem. If any of the group members could solve this problem I
shall feel highly obliged.
 
Top