473,394 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Update Count of records from one table to another based on criteria

I have two tables:

TrendMaster: EmployeeID, Joined_Period, Delay, Index, Branch

*Joined_period takes month eg: "April", "March"...

TrendSheet: Branch, April_Joined, April_Delay, April_Index, May_Joined...so on till March_Delay, March_Index

I need to update April_Joined with: Count of employees in TrendMaster for whome Joined_period is April and these need to be grouped as TrendMaster.Branch=TrendSheet.Branch

The query that i thought should work is:
Expand|Select|Wrap|Line Numbers
  1. UPDATE TrendSheet INNER JOIN TrendMaster ON TrendSheet.Branch = TrendMaster.Branch 
  2. SET TrendSheet.April_Joined = ( Select Count(*) from TrendMaster where TrendMaster.Joined_Period='April')
However, I get an error "Operation must use an Updateable Query"
Please suggest!
Nov 24 '09 #1
6 5851
Got the answer!
For anyone else who needs this, posting the query that worked:
Expand|Select|Wrap|Line Numbers
  1. UPDATE TrendSheet INNER JOIN TrendMaster
  2.     ON TrendSheet.Branch=TrendMaster.Branch
  3.    SET April_Joined=DCount("[EmployeeID]","TrendMaster","[Joined_Period]='April")
Thanx!
Nov 24 '09 #2
NeoPa
32,556 Expert Mod 16PB
A perfect example of why the CODE tags are so important. Whatever you got to work, wasn't that. It's missing the last closing apostrophe (single-quote) after 'April.

Thank you for having the courtesy to post back with your solution though.
Nov 24 '09 #3
NeoPa
32,556 Expert Mod 16PB
@arvarunar
I suggest you decide never to do such an update as it makes your database non-normalised. See Normalisation and Table structures.

If you decide that, after all you must, for whatever reason, then the approach you have suggested is about as good a one as you'll find. This is only an issue in Access mind. Most database servers don't suffer from this restriction and your original code concept would work fine.

Please think very carefully about your approach though. It is strongly recommended against (as you'll understand better when you've read the linked article).
Nov 24 '09 #4
@NeoPa
That apostrophe got missed somehow...I posted the same question on other forums...probably while copy pasting it got out...

Actually this is a very simple data and can be maintained and tracked easily using Excel. I chose to create the trend sheet in single click out of the data, thats why using access.

Also there are limits like this will be used by non-tech guys after I am done and resources are very limited. The output needs to be as is without negotiations or modifications.

Thanx for the article though...its universally useful..

There is another issue I am facing now...please help with that...
Expand|Select|Wrap|Line Numbers
  1. UPDATE TrendSheet INNER JOIN TrendMaster 
  2.     ON TrendSheet.Branch=TrendMaster.Branch 
  3.    SET April_Joined=DCount("[EmployeeID]","TrendMaster","[Joined_Period]='April'")
I am getting the April data through this, however the Branch does not match.

Output for this is:

Branch April_Joined
Ahmedabad 6
Mumbai 6
Chennai 6
Kochi

My TrendMaster had 6 records 1 for Ahmedabad, 3 for Mumbai and 2 for Chennai. This query totalled all and updated the total to all branches found. However, I need a group by effect!
Please suggest!
Nov 25 '09 #5
NeoPa
32,556 Expert Mod 16PB
Let me first draw you attention to the edit comments I keep attaching to your posts when I have to go in and change them. Please use the tags in future as this is not optional.
Nov 25 '09 #6
NeoPa
32,556 Expert Mod 16PB
You need to change your DMax() call to look through only the records that match the Branch required :
Expand|Select|Wrap|Line Numbers
  1. UPDATE TrendSheet AS TS INNER JOIN
  2.        TrendMaster AS TM
  3.     ON TS.Branch=TM.Branch
  4.    SET TS.April_Joined=DCount("[EmployeeID]",
  5.                               "TrendMaster",
  6.                               "[Branch]='" & TS.Branch & "') AND "
  7.                               "[Joined_Period]='April'")
Nov 25 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
5
by: Cro | last post by:
Hello Access Developers, I'd like to know if it is possible to perform a count in an expression that defines a control source. My report is based on a query. In my report, I want a text box to...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
2
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the...
0
by: jon | last post by:
Hi there, I'm brand new to Access and may be trying to do too much too soon, but I wanted to get some expert advice on how the best way to go about what I am trying to accomplish would be. I...
1
by: mharis | last post by:
I'm using MS SQL and I'm challenged with how update a table based on the count of records from another. I have a couple transactions for an id and I want to count total number and multiply by 4 or...
2
by: mfaisalwarraich | last post by:
Hi Everybody, I am using the following code to get the recordset of an external database. Dim dbPatients As Database Dim rsCountPatients As Recordset ' to count number of...
7
by: BONES7714 | last post by:
Hello, This is my first post to any sort of forum although I've used them to learn the very little Access/VBA that I know so please forgive my ignorance. I work for the National Guard as Combat...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.