Printing Reports (Command Buttton)

drunkcrusher78

Registered User.
Local time
Today, 12:57
Joined
Mar 16, 2004
Messages
13
I have 7 different reports that pull information from a single query. The names are as follows:
RptChecklist
RptRightsform
RptCitation
RptAdminhearing
RptArrestaffd
RptPropertyRecord
RptMarshalsheet

In the main query, I have a primary ID field of Case Number, which is unique to each record in the query. The simple method that I would like to create, is for me to be able to click on a command button, it ask me to enter the Case Number, and it print ONLY the record from the query with that case number for that report.

Now, ultimately what I would like to do, is be able to click on a single command button, and it print each of the reports above, sequentually, by entering the Case Number and printing only that record. Some records are 2 pages, some are 4 pages long.

Please be simple in your response, Im still learning. I have played with the several of the Macro Commands, etc. but can't get it to filter only the record that I need.

Thanks in advance.
Oren Haydel
 
In the form you are running these reports from, insert an unbound text box that allows you to enter the Case Number. Name the control txtCaseNumber.

Then place a command button on the form to open the reports. Use the wizard to set the button up to open a report. Select RptChecklist as the report to open.

Then go into the code for the command button's On Click property and add the criteria at the end of the DoCmd line. There must be 3 commas between the document name and the criteria. The argument "acPreview" is in there assuming you want to preview the report before printing but it can be removed if you just want to print, but don't remove the comma.

stDocName = "RptChecklist"
DoCmd.OpenForm stDocName, acPreview, , "[CaseNumber] = " & Me.txtCaseNumber

Then simply duplicate these 2 lines changing the report name for each subsequent report. You could also do this with a loop but we'll keep it simple.
 
Last edited:
Open report

Ok, I added the necessary information like you described. The button opens the selected report in print preview mode. However no data is displayed. How does this method get the information from the query? And where is it calling for the field "Case Number" My field in the query is that name, with a space between words.

BTW I had to use the OpenReport command instead of the OpenForm command.


Oren Haydel
 
Oops, the OpenForm was kind of a typo. I just grabbed a piece of code from a form I was working on...


And where is it calling for the field "Case Number" My field in the query is that name, with a space between words.

DoCmd.OpenReport stDocName, acPreview, , "[Case Number] = " & Me.txtCaseNumber

I had it as "CaseNumber" because I never use spaces in my fields. Just add the space and try it out.
 
Last edited:
Sorry, I should have mentioned, that I already added the space to make it execute correctly. It just pulls up a blank report. When I open the report from Access directly, all of the data is there, but when I use the button, it is blank. I am putting in a valid case number for the search.

Oren Haydel
 
Seeing that the reports get their records from a query, is there any type of criteria set on [Case Number] in the query? Because that will override the report criteria.

Also, when the report opens (preview), hit the design view button and open the properties box. Look at Filter in the Data tab. It should read:

[Case Number] = (the case number you entered in the form)

Check that out and see.
 
I checked the properties of that form, and it displays the filter just like we set up:
[Case Number] = (the case number I entered in the form)

Still blank record in print preview.

I have no arguments or filters set on the query that I am aware of.

When I open the report directly from Access, it still displays all of my records.

Wow, this is harder than I thought!

Oren Haydel


+++++++++++++++++++++++++++++++++
This is how I have the form set up:
I have a small rectangular form that I named FrmReportmenu. It is a standalone form and is not bound or controlled.
I have my control buttons on that form.
I added the unbound text box like you said and named it txt.CaseNumber
On the on click property of the first command button, I placed the argument that we spoke about.
I then enter the case number to the record that I want, and click the appropriate command button. This opens the correct report, but it is blank.

Hope this helps
 
Last edited:
Yeah, that's a puzzler.

Another suggestion is to go into the query, and under criteria for Case Number enter:

[Forms]![FrmReportmenu]![txtCaseNumber]

If you try this, you'll want to remove the criteria in the DoCmd OpenReport line.

Did you name the text box txtCaseNumber or txt.CaseNumber? Make sure all your references to this control are consistent.


Otherwise, all I can suggest is to attach a sample of your database in a zip folder.
 
Last edited:
Here is a quick sample database I created that works like you want yours to work.

The case numbers you can enter in the form are:

12345
23456
34567
45678
56789
67890

Any time you enter one of these numbers into the form, the report will open with only that record.
 

Attachments

RichO

It works. I used this suggestion:
[Forms]![FrmReportmenu]![txtCaseNumber]
Placed it in the criteria field on the Query, and It works like a charm.

Thank You very much for your time.

Oren Haydel
 

Users who are viewing this thread

Back
Top Bottom