473,796 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

In Dire need of table manipulation help

69 New Member
Hello all.

I have a table in Access that has a check box as one of the fields. I want to write a query or code that will check or uncheck that box based on conditions met by other fields in the table. Here are the specifics as well as I can explain it:

I have the following table fields:

EmployerID
Group
Payroll
Yes/No

In the table I will have multiple instances of an EmployerID, one for each Group. Then there can be a monetary number in the Payroll field (or it can be 0). And the Yes/No field is the check box.

What I want to do is evaluate each group of records based on EmployerID.

If a given EmployerID has all ZEROs in the Payroll field for each Group I want to set the Yes/No to Yes(checked) for each record with that EmployerID.

If even one Payroll field for a given EmployerID has a value greater than ZERO I want to set the Yes/No to No(unchecked) for each record with that EmployerID (even those that have a ZERO Payroll).

I hope this makes sense. I don't care if it's done in a query or a module, as long as it works.

Any help will be greatly appreciated!
Thanks,
narpet
Nov 7 '06 #1
8 2175
MMcCarthy
14,534 Recognized Expert Moderator MVP
Hello all.

I have a table in Access that has a check box as one of the fields. I want to write a query or code that will check or uncheck that box based on conditions met by other fields in the table. Here are the specifics as well as I can explain it:

I have the following table fields:

EmployerID
Group
Payroll
Yes/No

In the table I will have multiple instances of an EmployerID, one for each Group.
Is your tables primary key EmployerID and Group together?


Then there can be a monetary number in the Payroll field (or it can be 0). And the Yes/No field is the check box.

What I want to do is evaluate each group of records based on EmployerID.

If a given EmployerID has all ZEROs in the Payroll field for each Group I want to set the Yes/No to Yes(checked) for each record with that EmployerID.
UPDATE TableName SET [Yes/No]="Yes"
WHERE Count(Group) = Count(IIf(Payro ll=0,1,0))
AND EmployerID=<som e value>;


If even one Payroll field for a given EmployerID has a value greater than ZERO I want to set the Yes/No to No(unchecked) for each record with that EmployerID (even those that have a ZERO Payroll).
Set the default value for [Yes/No] to "No"
Nov 7 '06 #2
narpet
69 New Member
Thanks for the help, but I'm not sure if this will work for me because I have to be able to change the Yes/No field without specifying an EmployerID. In other words, it needs to be able to make this change based on Group and EmployerID without calling a specific one...

example records:

EmployerID Group Payroll Yes/No
1 A $10.00
1 B 0
1 C 0
2 A 0
2 B 0
2 C 0

In this example I would want to set all of the Yes/No fields in the records for EmployerID 1 to No because one of those records had money in it.

I would want to set all of the Yes/No fields in the records for EmployerID 2 to Yes because none of those records have money in them.

I need to do it without having to specify EmployerID. There are thousands of records and it's not practical to specify any given criteria.

Any more help will be greatly appreciated.

Thanks,
narpet
Nov 8 '06 #3
Killer42
8,435 Recognized Expert Expert
Ok, despite the "top ten" listing I'm not an Access expert - just a dabbler. My SQL knowledge is at a very simple level.

However, to me it sounds as though you might want an aggregate query grouping records by employee ID, with a count of non-zero payrolls, or a subtotal of payrolls. To that, you should be able to JOIN (don't know which type) based on the count (or subtotal) being zero.

Does this sound reasonable?
Nov 8 '06 #4
NeoPa
32,579 Recognized Expert Moderator MVP
It does indeed Killer.
I just finished looking at this question and decided that it's something I can help with - when my brain is a little less tired than it is now.
If I haven't posted a helpful reply by tomorrow night (I hope you can wait that long), then you have my permission to remind me with a PM.
Nov 8 '06 #5
Killer42
8,435 Recognized Expert Expert
...aggregate query grouping records by employee ID, with a count of non-zero payrolls, or a subtotal of payrolls. To that, you should be able to JOIN (don't know which type) based on the count (or subtotal) being zero.
Um... actually, I imagine the "not zero" would have to be applied to the aggregate query before doing the JOIN - help me out here, someone.
Nov 8 '06 #6
NeoPa
32,579 Recognized Expert Moderator MVP
I don't know the name of your table so, for my answer, I'm using [tbl]. Replace all occurrences of this with your table name when you use it.

Expand|Select|Wrap|Line Numbers
  1. UPDATE [tbl] INNER JOIN (SELECT [EmployerID], (NOT Max([Payroll])) AS YN
  2. FROM [tbl]
  3. GROUP BY [Group]) AS subYN ON [tbl].[EmployerID] = [subYN].[EmployerID]
  4. SET [tbl].[Yes/No] = [subYN].[YN]
Now, I suspect this may fail with an error message about being an non-updatable recordset.
If that is the case then we are a little stuck and probably have to do something with a temporary table.
I'm afraid I can't test this myself due to not having your data available (or time for that matter) so post back your test results if you would.
Nov 8 '06 #7
narpet
69 New Member
You sparked my imagination and I ended up doing it the simple way.

I used a query to create a temporary table to put all the records where the sum of the Payroll for a given EmployerID was 0.

Then I used that temporary table to update the Yes/No field based on the records in the temporary table.

Works like a charm.

Thanks to everyone for the help and ideas.

narpet
Nov 8 '06 #8
Killer42
8,435 Recognized Expert Expert
You sparked my imagination and I ended up doing it the simple way.
If we provided ideas that inspired you to solve the problem for yourself, then that's probably the best result we could hope for. :)

Cheers!
Nov 8 '06 #9

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

Similar topics

2
11535
by: Mike | last post by:
My page populates a table with a list of names and other information from a JavaScript object. I receive changes (adds, change & delete) to that list, convert it into a JavaScript object. I do understand how to add the new names to the list. I have 3 questions: 1) How can I search through the table rows to find the rows to be changed or removed?
1
1472
by: VK | last post by:
Hello, I am currently doing a project on Access and am current stuck in the "search" process and hoping that you could help me out. I have got 3 tables designed. When the user clicks on search option based on the record # (not a combobox), services, location, date (all combo boxes) the particular record that is stored in the 'allinfo' table should be displayed. I would like to know how to fetch the particular record as the service...
5
1695
by: Seth | last post by:
I have one table of the form: Delivery Product 101 A 101 B 101 C 102 A 102 E 103 C 104 A
4
3493
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if substrings need be replaced, or one character needs be changed, what shall I do? Is it better to convert strings to UCS-32 before manipulation? But on Windows, wchar_t is 16 bits which isn't enough for characters which can't be simply encoded...
15
4646
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
0
2591
by: L'eau Prosper Research | last post by:
Press Release: L'eau Prosper Research (Website: http://www.leauprosper.com) releases new TradeStation 8 Add-on - L'eau Prosper Market Manipulation Profiling Tools Set. L'eau Prosper Market Manipulation Profiling Tools Set is a set of advanced tools that help Serious Traders analyze the market direction, market manipulative behavior and predicting the change of trend.
0
2353
by: L'eau Prosper Research | last post by:
NEW TradeStation 8 Add-on - L'eau Prosper Market Manipulation Profiling Tools Set By L'eau Prosper Research Press Release: L'eau Prosper Research (Website: http://www.leauprosper.com) releases new TradeStation 8 Add-on - L'eau Prosper Market Manipulation Profiling Tools Set. L'eau Prosper Market Manipulation Profiling Tools Set is a set of
5
1909
by: Andrew Hedges | last post by:
Wherein I attempt to debunk some myths about the relative merits of the two methods for programmatically adding content to a web page: http://www.newfangledtelegraph.com/blog/entry/the-need-for-speed-innerhtml-versus-dom-manipulation/ Cheers, -Andrew ----- andrew@hedges.name / http://andrew.hedges.name/
0
9683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9529
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10013
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9054
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4119
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.