Hi again!
The last post I put up has a bit more detail that you
kindly asked for, so I'd look at that first.
The reason for this second post is that I need another
shove on the Excel side of things. I've figured out
creating a recordset for the hospitals in Access... I'm
now not sure about the methodology of working with the
Excel file - i.e. how to specify which sheet/row the data
should be exported to. Do I use a combination of VBA in
the Access form followed by VBA created in Excel
workbook_open? Does the email part come into the
Access/Excel code - etc. It's not easy to find a simple
explaination for this on the net, and Northwind doesn't
help.
Thanks again Allan.
-----Original Message-----
Thanks for your kind words. I'm glad to help when it is
appreciated (but
tend to get annoyed when there is not even an
acknowledgement).
Re the grouping question:
1)My thought was that you include a column in the Access
query that would be
your header value (dependant on status). If you do this,
it seems that you
would only need one row/cell on your spreadsheet that
would show the
appropriate value based on your filter. Am I missing
something?
2)Can you give me a sample of what you visualize for the
heading, subheading
and detail ?
3)Are there any group footers?
Allan
message
Conditional formatting... spot on, didn't think of that.
I guess issues such as this are things that I can sort
out
when I get to work on it. I think you've explained
really
well that it is worth pursuing.
Regarding your thoughts on the queries I raised:
1. (Grouping levels stuff) - I currently use the switch
function to set what the field will show and what the
label will be (the label is actually a textbox) with the
criteria being the referral status. What you've
suggested
makes sense for the detail in the column. But I don't
know how I could get the Status to show as subheadings
rather than another column, and create a new header
beneath each subheading showing the calculated label
(dependant on status). If I'm right on this, I think
I've
got a workable solution - tell me if it can work/what
you
think:
In Excel workbook:
-Create 3 rows at the top showing the 3 different header
possibilities (dependant on status).
-Have the status in the final column and hide it. (sort
data by status and then referral key to enable hide
duplicates to work - con.formatting will also have to
look
at equal referral keys in the 2 rows)
-Put a filter on the hidden status column
-Create a combo box for patient to select status
(subheading)
-action from combo the relevant header row to be visible
and the status column appropriately filtered.
- This would have to be created for every sheet.
2. The above wouldn't require the breaks... otherwise
I've
done similar things before in Excel - it is getting the
status as a sub-heading that I don't know.
3. I might try looking through internet/helpfiles until
I
hit a hurdle - I've never actually had a coach/training
or
read an IT book.
You've helped me so much, I really appreciate all the
time
you must have spent and the advice that you have given.
I'm going to get to work on it. I'd value your thoughts
on my suggestion in 1. (If what I've written makes any
sense!).
Thanks Allan, there's a beer (or 2) waiting for you in
London!
I'll probably be back on for further problems...
especially in the emailing bits!
Basil
-----Original Message-----
Ah! This is where the superiority of Access over Excel
as a reporting tool
becomes evident. But this still may be doable. To
handle the suppression
of duplicates in Excel, you need to use conditional
formatting. See
http://www.contextures.com/xlCondFormat03.html#Duplicate
for an example of
how to do this. You could apply the conditional
formatting in advance to
the appropriate columns in your spreadsheet template.
Re some of your other questions:
[ The Referral Status grouping level effectively
converts
the field to
subtitles in each of the hospital reports.
some of the detail fields and Referral Status header
labels are calculated
textboxes that show different data
depending on the Referral Status (subtitle).]
You could handle this by formatting the column using
the
Switch function
within your query. (See Visual Basic help if you are
not familiar with the
Switch function. Access does a good job of hiding its
availability)
[There would also need to be a blank row forced between
each grouping stage
within the sheet - the detail size is variable so it
would have to be built
into the process - is it possible to run Excel VBA on
the workbook from
within the Access code?]
Yes, it is possible to use Excel VBA from Access. I'm
not sure how you can
handle the multiple break levels, however. I have some
ideas but would need
to see your report format before I could give you
suggestions.
[I have no idea what DAO/ADO recordsets are though -
but
I'll look into it
and learn - know any good sources?]
Maybe it was just me, but years ago when I was teaching
myself to work with
recordsets, I really struggled. And I was working from
a
book that was
highly recommended (written by Getz, Litwin and
Reddick). If this is your
first time working with DAO, automation of Excel from
within Access and
looping constructs, you would probably benefit from
working with a
consultant/coach to get you started and to help you
over
the hurdles.
Allan
message
Allan,
First of all, thanks so much - you're a star.
That sounds workable. I already have 5 seperate
queries,
and I use a filter (actioned in VBA if required) to
specify the hospital. I have no idea what DAO/ADO
recordsets are though - but I'll look into it and
learn -
know any good sources?
I think it would help to explain the grouping levels:
1st - Originating Hospital
2nd - Referral Status (or referral stage depending on
report)
3rd - Referral key (since 1 patient may have >1
appointment)
A couple of worries/doubts in it as a result...
The Referral Status grouping level effectively
converts
the field to subtitles in each of the hospital
reports.
some of the detail fields and Referral Status header
labels are calculated textboxes that show different
data
depending on the Referral Status (subtitle).
Would I be able to recreate this? There would also
need
to be a blank row forced between each grouping stage
within the sheet - the detail size is variable so it
would
have to be built into the process - is it possible to
run
Excel VBA on the workbook from within the Access
code?
Secondly due to the referral key grouping, I
set "Hide
duplicates" to yes on many fields in the report. Can
this
copy across?
If we can sort out the above queries - it sounds
great,
and I think I could manage it! Would even remove the
need
for email automation!
IF we can't sort out the queries above is it
feasible to
have 5 Excel workbooks set up for each report and
filter
the different Referral Statuses into seperate
sheets -
wouldn't fix the hide duplicates problem though...
and
would cause further work - would rather be able to
solve
the queries I think!
Thanks loads Allan.
Basil
-----Original Message-----
Basil,
The key question is whether you can represent the
data
from your Access
reports using queries. If so, the
TransferSpreadsheet
method should work.
The key to making the process more efficient is
using
VBA, in particular its
looping capability.
See if this makes sense for you.
- Create a template in Excel that has 5 sheets, one
for
each report type
- In Access, create 5 queries (or modify existing),
one
for each report.
For the WHERE clause of each query, use something
like "WHERE HospitalID =
Forms!frmSelect!cboHospitalID " (cboHospitalID
being a
combo box on the form
frmSelect)
- create a VBA procedure that loops through all the
hospitals using a DAO or
ADO recordset (e.g. recordset name = rsHosp)
- within the loop, you can create an Excel file for
each
hopital by doing
the following:
1) set the value of cboHospitalID = rsHosp!
HospitalID
2) reset a variable that contains the target Excel
filename e.g...\Excel
Files\[HospitalID].xls
3) use the Kill statement (see Visual Basic for
Applications help in MS
Access) to delete any prior version of the target
file
4) copy the source Excel template file to the target
file
using the FileCopy
statement
5) use the TransferSpreadsheet method to transfer
data
from each of your 5
queries (which will be filtered for the current
hospital)
to the appropriate
sheet in the target Excel file
6) e-mail the Excel file
7) move to the next hospital
Let me know if this sounds workable.
Allan
--
Allan Thompson
APT Associates/ FieldScope LLC
MS Office Automation / Measurement and Reporting
Systems
www.fieldscope.com
860.242.4184
in
message
Thanks Allan,
This sounds like the right kind of track I need
to be
on.
I am aware of how you can create a pivot form
which
can
be
opened up in Excel edit mode - this seems to hold
the
Excel file within the database (although I could
be
wrong) - it's not what I want but holding the
excel
file
internally might be useful to me. I'll give you
more
detail:
I work for a hospital. There are 30 hospitals
that
send
patients to us for treatment (these are
referrals).
When
with us, I have allocated information into
different
groups -
1. patients who we have only got the referral for
2. patients who we have seen at a clinic
3. patients who we have have agreed to admit
(booked
list)
4. patients who have been admitted
5. patients who we see at a follow-up clinic
Within these groups referrals can have a different
status
(there is a referral key which carries across all
activity) - eg. point 2 can be patients sent back
to
the
original hospital/patients on hold/Active patients
(waiting for appointment or outcome).
I have created 5 reports in line with the above,
and
introduced a grouping level to show the referral
status
(forces new page). (There is also a higher
grouping
for
hospital of origin).
Thanks for bearing with me on this...
I have a form that enables you to view all reports
or a
selected report - either showing all hospitals
within
them
or filtered by hospital.
Now is where I need help... they want to see the
report
in
Excel - ideally 1 workbook with 5 sheets (I'd
remove
the
page break for the status grouping - so all
statuses
will
be on the same sheet). But 5 workbooks would be
fine.
Now I would need to run through a process as
follows:
-Select 1st hospital in table
-run all 5 reports (shoved in Excel if poss) (if
have
data)
-attach them to an email
-send to email (held in the email fild of the
hospital
table)
-Select 2nd hospital...
This would be done weekly. As you can imagine,
the
reports would be referenced on many occasions -
and
I'd
rather not have 150 (30hospitals*5reports) Excel
templates.
Will the transferspreadsheet allow me to make this
work,
how?
I really appreciate you getting back to me on
this.
Many thanks,
Basil
-----Original Message-----
Mike,
Without knowing more about your data and Excel
reporting
needs, its hard to
give a definitive answer. The easiest approach,
and
hopefully the one you
can use, is to use DoCmd.TransferSpreadsheet (see
TransferSpreadsheet Method
under MS Access help). This command allows you
to
export
data from tables
or queries to Excel. Since you can use query
datasets,
the data you export
to Excel can be data joined from multiple tables,
calculated data, summary
data, and/or filtered data.. The Excel sheet
that
you
transfer to can be
setup as a template with the additional formulas,
charts,
etc already in
place. Macros or VBA code can be used to
automate
the
data transfer to
multiple Excel files.
If this approach sounds workable and you need
more
direction, let me know.
I can also suggest other alternatives if this
does
not
sound viable. The
automation of e-mails, if needed, shouldn't be
too
difficult either.
Allan
--
Allan Thompson
APT Associates/ FieldScope LLC
MS Office Automation / Measurement and Reporting
Systems
www.fieldscope.com
860.242.4184
"Mike T."