ALTERNATIVE FOR MUTIPLE UPDATE QUERIES?

P

pauld

I have Access 2003.

I have to assign a name to a group of items that fit certain paramenters,
like length and cost. (For example - if length is greater than 25 feet and
cost is greater than $100, assign all of the items in the database that meet
those parameters to Category A)

There are 25 groupings.

The parameters change periodically.

I've been using 25 separate Update Queries run under one macro to do the
updates.

But, it means I have to change the criteria of the Update Query for each
group every time there is a change in the parameters that assign an item to
one group or another.

Is there an easier/better way to do this?

Is it possible for me to set the value in a table and bounce the paramters
against this table to determine the Category and assign all of the items that
meet the parameters to that Catogory?

Many thanks for helping me figure this one out!
 
K

kc-mass

Set up a table with a field SQLStringText length 250

In that field put the text of the appropriate SQL string like:
UPDATE tblDimensions SET tblDimensions.Category = "A" WHERE
(((tblDimensions.Length)=25) AND ((tblDimensions.Cost)=100));

Create 1 record for each set of criteria and then run
through the table with something like:

Sub RunThroughSQL()
Dim db As DAO.Database
Dim RS As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb
Set RS = db.OpenRecordset("tblSQLString")
RS.MoveFirst
Do While Not RS.EOF
strSQL = RS!SQLStringText
DoCmd.RunSQL (strSQL)
RS.MoveNext
Loop
End Sub

Regards

Kevin
 
P

pauld

First, let me thank both of you for your responses.

I have approximately 25 different categories (actually called classes A-Y)

The 2 criteria that determine which class an item is assigned to are each
different (25 different set of criteria)

I was wondering about creating a table with the criteria and then using
those criteria in Update Queries that use the value in the table field as the
search criteria in the query.

For example, if I create a table with "cost" as a field and make its value
100, can I reference that table field in the Update Query? The Update Query
would look at all items in the database and update the class of those items
(with a cost = 100) to the new class.

That way I can change the table value (via a Form) and simply run the Update
Query every time there is a need to make a change

I hope I'm asking the question clearly.

By the way, I am not working with SQL. I don't understand how to do it. I am
strictly trying to do this with the standard Update Query. Is it possible?
 
P

pauld

Ken,

Thanks for your response.

There are 25 classes and each class has unique criteria. There is no chance
of overlap.

I've been using a Macro that runs 25 Update Queries when I have to make
changes. I usually have to change 3-4 Update Queries each month.

I sort of understand the explanation about not using an Update Query, but
how would I run an update on the entire database?

The two tables in question don't have similar sets of value. The only common
item would be the "class" of the item.

I am not SQL-conversant and appreciate your plain "english" clarifications :)

Could you give me a little more direction on how to do this?

Thanks.



KenSheridan via AccessMonster.com said:
It would be possible, but the referenced table would have to include all
possible combinations of the criteria. You haven't really given us enough
information to say what this would imply as regards the detailed contents of
the referenced table, but it depends on how many different attributes make up
the 25 different criteria for determining the category.

Taking your simplest possible example of cost being the sole determining
factor for a category, lets say items with a cost of 100 are category A, of
200 category B of 300 category C and so on. The table would then simply have
columns Cost and Category with values like so:

100.00 A
200.00 B
300.00 C
<and so on>

But this assumes every item has a cost of 100, 200, 300 etc. If you specify
a range of costs with LowerCost and HigherCost columns in pace of the Cost
column then the table would be:

100.00 199.99 A
200.00 299.99 B
300.00 399.99 C
<and so on>

so items with intermediated costs can be accommodated.

If you then start introducing other criteria then things begin to get a
little more complicated. You gave length as an example in your first post,
so lets say that for each item, if the length is over 25 this puts the item
in another category, D, E or F say for each cost range, then you also need
LowerLength and HigherLength columns in the referenced table.

0 25 100.00 199.99 A
25.01 1000 100.00 199.99 D
0 25 200.00 299.99 B
25.01 1000 200.00 299.99 E
0 25 300.00 399.99 C
25.01 1000 300.00 399.99 F
<and so on>

where the 1000 values are artificially high upper length values more than no
item will ever be, so the range 25.01 to 1000 in effect means any length more
than 25.

Now lets say you have a category X which is dependent solely on a cost of
1000 USD or more regard less of length an further crow would be added to the
table:

0 1000 1000.00 1000000.00 X

where in this case the one million HigherCost value is an artificially high
one which no item will reach, so the cost range 1000.00 to 1000000.00 in
effect means 1000 USD or more or more, and the length range 0 to 1000 in
effect means any length.

If you introduce other criteria than cost and length the number of rows in
table is growing to grow as you'll need to combine these criteria with the
above in the same way that the length criteria were combined with the cost
criteria in the above example. Just how much it will grow and how manageable
the table would thus be depends on the number of determining factors involved
and the number of combinations of those factors. In fact, even with a large
number of determining factors and combinations of them it is possible to fill
the table without having to enter each row one by one, but this does require
building and executing an 'append' query in code behind an unbound dialogue
form in which the values for the different parameters. You have indicated
that you are not comfortable with SQL, so that might be a challenge, and I
would not want to mislead you into thinking it’s a trivial task.

In the above examples each category is determined by one combination of
factors only, but there is no reason of course why one category cannot be
determined by more than one combination of criteria, e.g. a lower length and
higher cost might put an item in the same category as one with a higher
length and lower cost.

So, whether it can be done or not really depends on just how easy it is to
firstly fill the ItemCategories table, and then maintain it as you change the
parameters over time. You would of course use a form bound to the
ItemCategories table for this to provide a user-friendly interface, but it’s
the really the number of rows which the table would require which is the key
factor, as these must not be self-contradictory, otherwise you could find
that a row in the Items table has more that one match in the ItemCategories
table.

If you believe the table can be correctly filled and managed thereafter, then
you could execute an 'update' query by joining the Items table to the
ItemCategories table and update the Category column in Items with that in
ItemCategories. By using ranges of values the join is not a simple one which
can be created in query design view, but you could first create a query in
design view using straightforward joins such as Items.Cost = ItemCategories.
LowerCost etc, then go into SQL view and amend the join expression in each
case to (Items.Cost BETWEEN ItemCategories.LowerCost AND ItemCategories.
HigherCost) etc. Note that enclosing each BETWEEN….AND expression in
parentheses is crucial here. So some fairly simple editing of the SQL would
be all that's required.

However, the main point here is that if it is possible to have the
determining values in a separate table, then you do not need to execute an
update query at all. The reason for this is that the Items table would then
redundantly contain the category for each item, so, dispensing with the
category column in Items and simply joining Items and ItemCategories in the
same way as you would for an UPDATE query but this time in a SELECT query
would give you the category for each item. When the determining factors for
a category change its then a case of just editing the ItemCategories table.

What the ItemCategories table would really be doing here is modelling the
relationship between Items and Categories, so you should also have a
Categories table, with just one column and 25 rows. This allows referential
integrity to be enforces so that ItemCategories can only contain legitimate
Category values, A-Y. You are probably familiar with a many-to-many
relationship being modelled by a table in this way (sometimes called a
'junction' table) but in this case the relationship is one-to-many,
Categories being related one-to-many to ItemCategories, and ItemCategories
being related one-to-many to Items, i.e. each item can be in only one
category at any one time, but each category can encompass many items.

Ken Sheridan
Stafford, England
First, let me thank both of you for your responses.

I have approximately 25 different categories (actually called classes A-Y)

The 2 criteria that determine which class an item is assigned to are each
different (25 different set of criteria)

I was wondering about creating a table with the criteria and then using
those criteria in Update Queries that use the value in the table field as the
search criteria in the query.

For example, if I create a table with "cost" as a field and make its value
100, can I reference that table field in the Update Query? The Update Query
would look at all items in the database and update the class of those items
(with a cost = 100) to the new class.

That way I can change the table value (via a Form) and simply run the Update
Query every time there is a need to make a change

I hope I'm asking the question clearly.

By the way, I am not working with SQL. I don't understand how to do it. I am
strictly trying to do this with the standard Update Query. Is it possible?
If the parameters which determine the category are the same set of attributes
in each case then this is a relational issue rather than an update one.
[quoted text clipped - 66 lines]
Many thanks for helping me figure this one out!

--



.
 

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