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

Sum in combobox

reginaldmerritt
201 100+
Hi,

Don't know if this is even possible but someone out there might be able to tell me otherwise.

I have a table with a list of names, lets call it TBEmployees. I use this table to list all employees in a combobox.

The Employees are linked to another table, lets call it something like TBSite. Employees can work in many different sites lots of times, therefore they can appear in TBSite many times. TBSite has a field called AreaID, where a number is used to represent the Area.

Is it possible for the combobox mentioned above to list not only the Employees but also the number of times their name shows up in TBSite with a certain AreaID?

So essentially the combobox will list each employee plus it will sow the number of times that Employee has worked at a particular Area.

Is this even possible?

Any help would be great.

EDIT:
I'm guessing that the comobox would need an expression something like:

DCount(["EmployeeID]","[TBSite]","[AreaID] = 2 And [EmployeeID] = " & ????? )

Where ??? is the EmployeeID in the combobox or rather the record in the recordsource for the combobox
Sep 24 '10 #1

✓ answered by Mariostg

Hi reginaldmerritt

That is why I said I don't know your table structure...
I obviously used wrong table/field names. I assumed you are familiar with the query designer and your question was more about whether or not you can have more than one column in the combo box. Sorry.

Here is a second guess
Expand|Select|Wrap|Line Numbers
  1. SELECT TBEmployees.EmployeeID, Count(TBSite.EmployeeID) AS CountOfTBEmployees
  2. FROM TBEmployees INNER JOIN TBSite ON TBEmployees.EmployeeID = TBSite.EmployeeID
  3. WHERE TBSite.AreaID=2
  4. GROUP BY TBEmployees.EmployeeID;
  5.  
I added a where clause that should take care of your counting if areaID=2. But again I am guessing your table design but it should give you an idea.

And yes, an aggregate is one of those functions like count, sum, average, etc...

On a side note, you should consider dropping the s at the end of your table name. Unless all tables do have an s, it gets confusing to remember which one is plural and which one is not.

Cheers.

9 2121
Mariostg
332 100+
You should build a query that would populate the employee along with the count of employeeId from the TBSite table. Then source your combo box with this query. You can have more than one column in the combo box.
I don't know your table structure, but it could the query would look like this
Expand|Select|Wrap|Line Numbers
  1. SELECT tblEmployee.EmployeeID, Count(tblSite.tblEmployee_id) AS CountOftblEmployee_id
  2. FROM tblEmployee INNER JOIN tblSite ON tblEmployee.id = tblSite.tblEmployee_id
  3. GROUP BY tblEmployee.EmployeeID;
Sep 24 '10 #2
reginaldmerritt
201 100+
Thanks Mariostg, sorry for the late reply.

I can see from your suggestion how that might count the number of times an employees id would appear in the table site. What I really need it the count to only count if the employee id appears in the table site and uses a certain area id.

I tried to just use the SQL you suggested, but i got the following error.

"You tried to execute a query that does not include the specified expression 'EmployeeID' as part of an aggregate"

I don't even know what an aggregate is, some sort of total figure or something I guess. Any ideas on what I'm doing wrong?
Sep 28 '10 #3
Mariostg
332 100+
Hi reginaldmerritt

That is why I said I don't know your table structure...
I obviously used wrong table/field names. I assumed you are familiar with the query designer and your question was more about whether or not you can have more than one column in the combo box. Sorry.

Here is a second guess
Expand|Select|Wrap|Line Numbers
  1. SELECT TBEmployees.EmployeeID, Count(TBSite.EmployeeID) AS CountOfTBEmployees
  2. FROM TBEmployees INNER JOIN TBSite ON TBEmployees.EmployeeID = TBSite.EmployeeID
  3. WHERE TBSite.AreaID=2
  4. GROUP BY TBEmployees.EmployeeID;
  5.  
I added a where clause that should take care of your counting if areaID=2. But again I am guessing your table design but it should give you an idea.

And yes, an aggregate is one of those functions like count, sum, average, etc...

On a side note, you should consider dropping the s at the end of your table name. Unless all tables do have an s, it gets confusing to remember which one is plural and which one is not.

Cheers.
Sep 29 '10 #4
reginaldmerritt
201 100+
Thanks,

I can see how adding the where clause will give the functionality I need.

Excellent tip on the table names, I have found this a problem before.

Using the following I still get the same error as mentioned before.

Expand|Select|Wrap|Line Numbers
  1. SELECT TBEmployees.EmployeeID, Count(TBSite.EmployeeID) AS CountOfTBEmployees
  2. FROM TBEmployees INNER JOIN TBSite ON TBEmployees.EmployeeID = TBSite.EmployeeID
Sep 29 '10 #5
Mariostg
332 100+
Obviously there you need the GROUP BY clause. When you use aggregate function, you must include in that GROUP BY clause the fields that are part on the SELECT statement that are not aggregate. Not sure if you get my wording here...
Sep 29 '10 #6
reginaldmerritt
201 100+
Ah i see.

I miss understood the purpose of 'Group By'.

Mariostg, thank you this works perfectly. Sorry for my slow up take, i've not worked with SQL directly much.
Sep 29 '10 #7
reginaldmerritt
201 100+
Sorry another question.

I want to create a display that will show each employee and the areas they have worked in.

I could create a query with a different where statement for each area. Using the query you have helped me with.

But what I would really like to do in addition, is to show each employee with a column for each area. Does that make sense?
Sep 29 '10 #8
Mariostg
332 100+
SQL can be query at times, but it is powerful.

You may want to start a new thread for your next question as it does not seem to be related to combo box. And since this thread is marked solved, there is little chance people will come to try to help.

In any case, not sure I get your question, but if you want say employee names on rows and area of work on columns, you are looking at a crosstab query. You can use the query designer for this.
Sep 29 '10 #9
reginaldmerritt
201 100+
Thanks, I'll have a look into crosstab queries. If I need any help I'll make a new post.
Sep 29 '10 #10

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

Similar topics

13
by: Mr. B | last post by:
Here's the situation... You've a combobox with Items already added. Say they look like this (or even lines of text): 10-00-232 10-00-256 10-01-006 10-01-213 10-02-200
7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
1
by: anonymous | last post by:
I've been trying to put a them, please help me out. Here's the major parts of my code: public Form1() { DataSet myDataSet = new DataSet("myDataSet"); DataTable testTable = new...
3
by: PeterZ | last post by:
G'day, After doing much searching and pinching bits of ideas from here there and everywhere I came up with a fairly 'clean' solution of including a comboBox into a dataGrid column. You can...
3
by: TT (Tom Tempelaere) | last post by:
Hay there, I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one (I hope .NET 2.0 supplies one). I based it on this article:...
2
by: Don | last post by:
I've looked high and low for some code that will allow me to have a combobox with a flat borderstyle. I found a few examples, but nothing that was really usable for me. I had the following...
0
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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
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,...

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.