Hi Todd,
(Don't we just love those last minute boss requests that have to be done
'yesterday'!
)
Alright, it probably is a little more complex than first thought, but no
major obstacle. As usual, there's a number of ways to achieve this depending
on your personal skill level/preferences. (Sorry, if this gets a bit long,
bear with me ...)
One caveat to start with; Its a bit difficult without knowing the schema,
structure, tables etc. of your Access dB, but I'll try to be as generic as I
can. (Normally, I would design the dB with the end-user reports required in
mind at dB design time - a lofty goal and not always possible, I know!).
Tip 1: Whilst it is probably more efficient, your queries do not have to
reside in the Access dB. You can build a separate/specific query for each
QueryTable should you so wish. (The relevant property of the Excel QueryTable
object is '.CmdText'). If you have installed MSQuery as a part of Excel, the
'Import Data Wizard' can call MSQuery to build the SQL Query statement
required for each QueryTable (and automatically set the .CmdText property).
MSQuery has a grid-like 'query builder' that should be very familiar to
Access users. Of course, you will need to create a query connection to your
Access dB (once only).
Option 1: Create a single QueryTable on a single worksheet of your workbook
to populate and refresh all detailed data for all credit managers. Use a
'Group By' clause in your SQL query statement to group (and sort) by credit
manager. Then after the query is refreshed on your worksheet, you can use
Excel's 'Group and Outline' and/or 'Subtotals' to summarize and total the
refreshed data (automatically). You can then show/print totals only or detail
and totals as you or your boss wish.
Option 2: If you really prefer a separate worksheet for each CM, then you
will have to create a separate QueryTable (with a separate, but similar query
statement) for each. (The key here is the use of criteria in the 'Where'
clause of each of the SQL statements built. For example, "Where [Access dB
credit manager field name] = 'credit manager name' (or ID)". The downside
here is that its somewhat 'hardcoded' and fixed. As soon as a new credit
manager is employed or terminated, your model 'breaks' and requires your
effort to fix and maintain.
Tip 2: Set the option to 'Refresh on Open' to true for all QueryTables
created. Then when you open this workbook, Excel will ask you if you want to
refresh the QueryTable data (yes automatically, in the background too!).
Tip 3: CountIf and/or SumIf Excel functions may also be useful on your
summary worksheet. (Likewise DSum and/or DCount).
The other option is that this can all be automated programatically by using
VBA - if you're confident/experienced with VBA and a little SQL. (This can
also cover and automate the problem mentioned above of new starters/leavers).
Let me know how you get on.
HTH and Regards, Sean.
tamxwell said:
Hi Sean,
It's actually Todd Maxwell, I fat fingered my own name, image that. I do
believe you are correct. Last night it click, hey just import it. I did a
trial run but to no avail. The answer is there I just need to "experiment".
The database UNION ALL queries I built are complex, it would have been nice
if my boss would have told me he need this for his own usage. I could have
built a query based on his requirements, but the DB is finished and online. I
might have more questions for you I hope you don't mind.
Thanks again,
tamxwell