Record count of all related tables...possible? (1 Viewer)

theKruser

Registered User.
Local time
Today, 06:44
Joined
Aug 6, 2008
Messages
122
I have a table that has multiple related tables. I am trying to display (in a from) the total record count of all related tables per record in the main table, but I do not know how to build the query...or if I should be using VBA. For example suppose:

tblCompany
-CompanyID (PK)
-ParentCompanyID (used for sections within the company, using CompanyID as FK)
-CompanySectionName​

tblPayable
-PayableID
-Data1 (etc, etc)​

tblRecievable
-RecievableID
-Data1 (etc, etc)​


Desired Result (simulated table with "|" as delimiter):

CompanyName | Payable | Recievable

CompanyA | Total # Payable | Total # Receivable
-Section1 | Payable | Receivable
-Section2 | Payable | Receivable

CompanyB | Total # Payable | Total # Receivable
-Section1 | Payable | Receivable
-Section2 | Payable | Receivable

Any help would be greatly appreciated
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:44
Joined
Aug 30, 2003
Messages
36,133
You could do it on the form with a DCount(), which would probably be easiest if there is only one company displayed at a time. If more, that could be a performance hog. You could also create a totals query that counted by customer, and join that query to the main table in another. You could use VBA, but I probably wouldn't. You'd only want to do it if the form was in single form view, and you'd use the current event.
 

theKruser

Registered User.
Local time
Today, 06:44
Joined
Aug 6, 2008
Messages
122
Thank you for your reply. What I am looking for is a "Status Page" for display of information only. I want this to be a dynamic page, so when a new Company is added, it automatically displays.

Can you please throw a quick example of how you would go about this? I will tailor it to my needs, but I am just not sure how to even begin setting it up with DCount() in a query.

Thanks again for your help.
 

theKruser

Registered User.
Local time
Today, 06:44
Joined
Aug 6, 2008
Messages
122
If at all possible, can you please help me build a crosstab query? That would be the best solution to my issue...just not sure how to accomplish it.

Thanks.
 

vbaInet

AWF VIP
Local time
Today, 11:44
Joined
Jan 22, 2010
Messages
26,374
Have you even attempted doing what was nicely explained in the link provided? Or explored the other ideas given by Paul?
 

theKruser

Registered User.
Local time
Today, 06:44
Joined
Aug 6, 2008
Messages
122
Yes...I tried both. Couldn't get it to work. I just wound up creating two queries for each table, one that pulled date and PK and the other that called a function to limit responces then count PKs. I then created a query to tie company to each count query. Wound up with 49 queries, but that was the only was I could figure it out.

(That's why I asked for an example)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:44
Joined
Aug 30, 2003
Messages
36,133
You asked for an example without providing one yourself to build on. You expect someone to build a database from scratch that matches yours, populate it with test data, and create this process? I assumed you were asking vbaInet anyway, since that was the most recent response. I got out of the way.
 

theKruser

Registered User.
Local time
Today, 06:44
Joined
Aug 6, 2008
Messages
122
My intention was not to be abrasive.

I supposed I should have articulated my question a bit better. What I was asking was just for an example of the code structure one would use to achieve the desired result. i don't want anyone to have to build anything at all. I have found that I learn more if I ask for an example of the code then try to hone it as required.

I am certain there are many that just want people here to solve their problem for them. I fail to take that into account from time to time. My request, albeit clear in my mind, was not properly verbalized with the acts/requests/wants of others in mind.
 

vbaInet

AWF VIP
Local time
Today, 11:44
Joined
Jan 22, 2010
Messages
26,374
I assumed you were asking vbaInet anyway, since that was the most recent response. I got out of the way.
Paul, you know that I value your input always so please don't feel I have hijacked your thread when I post a reply :)

@theKruser: What we would like to see is your effort and then we can guide you into fixing the problem. The link is quite easy to follow. You don't need a crosstab query.
 

theKruser

Registered User.
Local time
Today, 06:44
Joined
Aug 6, 2008
Messages
122
@vbaInet

I agree, the link is very basic and easy to follow. I understand how to create a totals query and how to tie one query to another for elimination processes.

I was just under the assumption that my goal would be easier to accomplish than the way I accomplished it. All-in-all, I now have the data I need, and I agree that a crosstab was not needed. It was just me thinking through the problem at hand. I thought that would be the best route simply due to the amount of tables I needed to join.

It is no big deal now. What I have might not be the best way, but it works.

Thank you for your time and help.
 

Users who are viewing this thread

Top Bottom