Results 1 to 6 of 6
  1. #1
    doug c is offline Novice
    Windows 7 32bit Access 2002
    Join Date
    Dec 2016
    Posts
    3

    Update query-multiple updates different criteria in different fields

    Hi all,


    New member.
    I almost don't know how to ask this but here goes I have tried a search with no result.

    I have a table (curmonthsale) with fields:

    pnum
    report date
    sales amount.

    I have linked this table with another table (sale) with fields:

    pnum (the linked field)
    jan
    feb
    mar
    apr
    may
    jun
    jul
    aug
    sep
    oct
    nov
    dec

    I need to do an update query that updates the fields in (sale) according to multiple criteria. Like:

    when (curmonthsale) linked pnum matching pnum in (sale) and report date = "2016/01" updates the jan field to sales amount from the (curmonthsale)

    I can do this query for one update at a time or in an IIF statement (7 limit), but i would like to do all the months in one update query.

    In other words do all the updates in one query. if report date (curmonthsale)= 2016/01 than update Jan (Sale) with sales amount plus if report date (curmonthsale)= 2016/02 than update Feb (Sale) with sales amount, plus all the other months.

    I don't know VBA at all, but can do some limited SQL. I do most my work in design view but have enough (barely) knowledge to do and edit the SQL view.

    Hopefully I have worded this question properly and not too dumb.

    Thank you for your help,
    Doug

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I think your table design(s) violate most rules.
    I recommend you review Normalization. and wikipedia
    Getting your tables and relationships designed to meet your requirements and follow Normalization rules will simplify your database activity.

    You might try watching some free video tutorials by Dr.Daniel Soper that will help you with the concepts.

    Intro to Database
    The Relational Model
    Data Modelling and the ER Model

  3. #3
    doug c is offline Novice
    Windows 7 32bit Access 2002
    Join Date
    Dec 2016
    Posts
    3
    Thank you Orange,
    I get these tables from someone else (state agency) and I don't think they are going to change them any time soon. They want the data back in the sale table in those fields. I am doing this for a friend as a favor who found out I knew a little about databases from some time I spent on DBASE IV about a hundred years ago.
    Doug



    Quote Originally Posted by orange View Post
    I think your table design(s) violate most rules.
    I recommend you review Normalization. and wikipedia
    Getting your tables and relationships designed to meet your requirements and follow Normalization rules will simplify your database activity.

    You might try watching some free video tutorials by Dr.Daniel Soper that will help you with the concepts.

    Intro to Database
    The Relational Model
    Data Modelling and the ER Model

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I would think you need an append query instead of an update query.

    Really need to see the dB, but since you say you cannot change the table structures, I see 3 options:
    1) Maybe you could create a crosstab query on table "curmonthsale", and use it in an append query and append(update?) table "Sales".
    2) Use VBA to loop through table "curmonthsale" and append/update table "Sales". (my preference)
    3) Manually make the changes to table "Sales".

  5. #5
    doug c is offline Novice
    Windows 7 32bit Access 2002
    Join Date
    Dec 2016
    Posts
    3
    Thanks Steve!
    I will try your ideas and get back to you.

  6. #6
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    159
    I admit I don't understand the structure, and need to see the DB. I'm especially foggy on the Table CurMonthSale - what benefit is there in the linked pnum field (which can only yield January, February, etc.)? Couldn't you get that exact same month extracted from the adjacent field called Report Date?

    As I read it, it looks like you just want to see all the sales, grouped by each month, on a nice neat report. Best of luck to you.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Update Multiple fields with multiple criteria
    By rockell333 in forum Queries
    Replies: 8
    Last Post: 09-17-2015, 11:01 AM
  2. Replies: 5
    Last Post: 03-05-2014, 09:59 AM
  3. Replies: 7
    Last Post: 11-01-2013, 03:17 PM
  4. update query with multiple criteria help
    By mbellas21 in forum Queries
    Replies: 2
    Last Post: 06-12-2013, 02:27 AM
  5. Replies: 5
    Last Post: 04-05-2013, 12:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums