View Full Version : Specific data for single reports


Krispy
07-21-2009, 06:05 AM
Hi all,

I've come here out of sheer desperation as I usually like to work things out for myself, but am wasting a lot of time and energy trying fix something which may not be fixable.
Have had a good read of relevant threads here and got a couple of ideas from them, but wonder whether anyone can advise before I continue with the wall head-banging. :(

Am in the process of designing health service database and really want it to be super-user friendly as they've had to put up with interim thing full of bugs since 2005. As I result I may be trying too hard where a simple solution might be better. Am using Access 2003.

System of working is thus:
many patients
many episodes for patients (periods of time when they need the service)
many referrals for each episode

Have therefore set up 3 tables; patients, episodes, referrals, each with unique ID, linked. Queries all work so structure seems sound.

One of the most important parts of this system will be a report which gives info to outside parties. I have it looking good - and it's based on:

1) query on 'patients' with all fields selected but no criteria
2) subreport - source query on 'episodes' with all fields selected but no criteria
3)subreport 2 - source query on 'referrals' with all fields selected but no criteria.

This report works (ie shows 1 patient, 1 episode, 1 referral) when criteria is entered manually (for test) into the source queries. So I know the report is okay.

What I had in mind to feed the report was this lovely little form which helps the user to select the patient by surname, then episode (showing only those episodes available to that patient) and then referral (showing only referrals for that episode) - in 3 neat combo boxes.
Then there's a button which previews the report based on the values in those combo boxes.
This form does what it should. It displays the right selectable data (event procedures all good). However the 'print' button does NOT do what it should - it shows every patient in the table, and if the user were to print, they'd be sending thousands of records to the printer.

I'm pretty sure the code works, so it seems that the values aren't being returned correctly to the 'where' clause. :mad:
I got help with the code syntax from someone clever. :o

The point is I suppose, am I making this more complicated than it need be?
I like the idea I read elsewhere in this forum about printing straight from a button on the form, using those fields. Except I don't know how to tweak that code in the 'where' criteria in query view.

In short, what's the best way to print 1 record from a 3-table report based on 3 queries?
Any advice would be most gratefully recieved.


I would describe my geek 'level' as intermediate. :)

Kryst51
07-21-2009, 06:11 AM
Can you post the code behind the preview button and the print button?

Krispy
07-21-2009, 06:32 AM
Can you post the code behind the preview button and the print button?
I certainly can but it won't be until tomorrow when I'm back at work.
Tho I can recall it's a DoCmd OpenReport reportname, acpreview, where...[PRN] = & me.patientselect AND...[ERN]= & me.episodeselect AND [RRN]= & me.referselect

Sorry, I can't possibly remember all the punctuation syntax that goes inbetween :confused:

Kryst51
07-21-2009, 06:35 AM
What I'm wondering is if the button that works (Preview) can give you the code needed to make the Print button work as well. Meaning whatever is causing the preview button to filter should also be applied to the pring button. I don't know if that is what the problem is, but if I were looking at things, that would be the first place I would check.

Krispy
07-21-2009, 06:39 AM
No, the preview button doesn't work either. It just shows me the first record in the patients table, with every other record available in the nav bar.

Kryst51
07-21-2009, 06:44 AM
Then there's a button which previews the report based on the values in those combo boxes.
This form does what it should. It displays the right selectable data (event procedures all good). However the 'print' button does NOT do what it should - it shows every patient in the table, and if the user were to print, they'd be sending thousands of records to the printer.

Sorry, This gave me the idea that the preview report button did what it should and the print button did not. I am not great with VBA, so I am not sure if I can analyze the code that you posted. It's more complicated then I thought it would be (for my unstudied brain) but, You could set your query to pull the info from the loaded form and then set your report to pull from the query. Then make the button open the report and the correct filter would be applied.

I hope that this will work for you, but if not I hope that someone else can chime in with more help.

Krispy
07-21-2009, 06:56 AM
You could set your query to pull the info from the loaded form and then set your report to pull from the query.
That sounds great. Thanks.

Can you give me a hint how to do this?

Kryst51
07-21-2009, 07:17 AM
That sounds great. Thanks.

Can you give me a hint how to do this?

Your Welcome. :)

If you open your query in design view, go to the id field criteria and select build, then in the left box of the build dialog box find forms, click that, then click loaded forms, (Oh yeah, make sure your form is open, otherwise this won't work) Find the field namd in the 2nd box and double click. Then click OK, and Save your query. This will make the query return whatever is showing on the form. Then on your report. Make it's source be that query. Place a button on your form that just opens the rejport and it should open correctly as the filters are directly built into the query and is pullinf from your open form.

Krispy
07-21-2009, 07:25 AM
Wonderful! I never knew it could be that simple. :D
(Actually, I didn't know there was a build function in queries, of course I should've realised cos it's so Microsoft - it writes itself! - sometimes):)

Thank you very much for your input, I will try it tomorrow and report back.

And of course if anyone else has any creative ideas, I'm eager to learn.

I'm glad I came now.

Kryst51
07-21-2009, 07:27 AM
Wonderful! I never knew it could be that simple. :D
(Actually, I didn't know there was a build function in queries, of course I should've realised cos it's so Microsoft - it writes itself! - sometimes):)

Thank you very much for your input, I will try it tomorrow and report back.

And of course if anyone else has any creative ideas, I'm eager to learn.

I'm glad I came now.

I certainly hopes that it works out for you! Please let us know if it does. And if it doesn't I am sure that others would be able to help more.

Krispy
07-22-2009, 01:41 AM
Well, this works like a treat and I am a VERY happy woman.:D
It took a bit of tweaking because of the subreports, but that was nothing...

Thanks ever so much for your help - you've probably saved me hours and hours of misery and frustration!
Plus - what could more user-friendly than a simple button?