473,387 Members | 1,578 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,387 software developers and data experts.

using the results from a count query

Hello everyone

Im new to this so im just going to explain my problem.

I have created a query that counts the number of times a supervisors
name appears in the client table. (Each client is assigned a
supervisor)

I then need to use that number generated to decrease the value in a
form. (Because a supervisor can only supervise a certain number
clients; this number can vary depending upon the amount of time each
supervisor has).

If anyone has any ideas of how i could do this, i would be very
grateful!

Thanks in advance

Katie Choy

Nov 13 '05 #1
5 1648
If your goal is merely to ensure that a single supervisor cannot have
any more than some fixed number of clients, you could just add code to
the BeforeInsert event of your (sub)form, and had it do a DCount of
records where the supervisor ID is the same as the supervisor ID in the
main form. If that's the case, then show a message (MsgBox) and reject
the insert (Cancel = True).

Nov 13 '05 #2
Thanks for replying so quickly.

I don't think i phrased the question very well.

I have a Client table with a field called "Supervisor" where i enter a
supvisor number.
I then have a Supervisor table where there is a field called "Number
to clients that can be monitored"

Every time a new client is entered into the table and a supervisor is
assigned, i need to decrement the value in the supervisor table.

I then need to create a report that shows the number od clients each
Supervisor has and the number clients that they can still take on.

Thanks again for the other reply, i feel it will be useful to prevent
allocating supervisors that are full.

K
Nov 13 '05 #3
> I don't think i phrased the question very well.

I have a Client table with a field called "Supervisor" where i enter a supvisor number.
I then have a Supervisor table where there is a field called "Number
to clients that can be monitored" Every time a new client is entered into the table and a supervisor is
assigned, i need to decrement the value in the supervisor table.


No you don't. You just put a maximum value of clients that this
supervisor *can* monitor in the supervisor table. then if you do a
DCOUNT() on the Clients table with that supervisor's ID as the
argument, you'll get the number of clients that supervisor is *already*
supervising. And then that's where the BeforeInsert comes in. Okay,
so you don't have a Main/Sub going on. You can do it all from the
Clients form. Here's the code I used to do it....
Private Sub SuperID_BeforeUpdate(Cancel As Integer)
If DCount("[SuperID]", "tblClient", "[SuperID] =" & Me.SuperID) =
DLookup("[MaxClients]", "tblSupervisor", "[SuperID] =" & Me.SuperID)
Then
MsgBox "This supervisor is already at max." & vbCrLf & "Please
assign to another supervisor."
Cancel = True
End If
End Sub

the DCOUNT gets the number of clients the given supervisor is already
supervising.
the DLOOKUP get the MAX number of clients the given supervisor can
supervise.
If the two numbers are already equal, the Supervisor is already working
at capacity and cannot have any more cases added. So I reject the
update to the chosen value (the supervisor(ID)) and prompt the user to
assign another supervisor. No need for a main/subform.

For the report, you can either do a summary for each supervisor and
show just the counts (MaxCaseload vs. CurrentCaseload) where
CurrentCaseload would just be the number of child records (Cases) the
supervisor has. Remaining slots or whatever is just Max-Current.

Nov 13 '05 #4
Oh, forgot one thing. If you want to show the supervisor's current
caseload on the form, you can just add an unbound control (just drop a
textbox on the form) and then set it's control source to
DCount("[SuperID]", "tblClient", "[SuperID] =" & Me.SuperID)

where "SuperID" is the SupervisorID field on your open form. One thing
you should be aware of - running update/insert queries will bypass this
check. (One place where Oracle is MUCH better than Access - it has
real table-level constraints and checks, whereas Access really has
little more than integrity checking).

Nov 13 '05 #5
Thanks for that, works brilliantly!

K

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Michael Krzepkowski | last post by:
All, I have a view that returns the following values: Item Vendor 70807 1234 70807 5678 If I am looking for items that have more...
2
by: Stan | last post by:
Hello all, I'm looking for some hints as to how to use the results of a query in another query. I assume I'm 'thinking' wrong in how to solve this, so I'm hoping someone can clobber me and send...
2
by: Stephen | last post by:
Hello all Run into a problem with a count query in access. It seems to count either all the results or none depending on criteria even though I have a query that selects the difference in...
2
by: commanderjason | last post by:
This seems like a very simple question but i have never been able to find an easy answer to it. I have a user table and i do a join with another table, we'll call the other table a results...
2
by: Daniel Di Vita | last post by:
I have created an ASP.NET page that allows the user to page through a result set. I need to expand on this. On that same page I a filed where the user can type in a search string. When they click...
3
by: Auddog | last post by:
I have the following query that works in mysql: select id, order_no, price, count(item_no), sum(price) from production WHERE item_no = '27714' group by item_no; When I setup my query in php,...
1
by: erick-flores | last post by:
Hello all I have a linked table using ODBC. When I tried to do Count() and Sum() for this linked table (onw of the field in the table is name "total") the form takes forever to gives me the...
1
lwwhite
by: lwwhite | last post by:
When a user clicks OK on form "SelectDefaults," I want to open form "Welcome" if the results of query "qry_todo_overdue" = 0 or form "OverdueToDo" if the results >= 1. First, I assume that I need to...
1
by: veaux | last post by:
Might not have explained this correctly in subject, but query results look like below: Name ID Phone Bill 001 123 Bill 001 234 Bill 001 ...
1
by: ramprat | last post by:
Hi, I'm trying to use the results from a select query as a way to limit the records that I update with my update query and it seems like it should work but I keep getting a "Operation must use an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.