Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Preview a report from data in a form - Access 2003

Posted on 2006-06-13
5
Medium Priority
?
256 Views
Last Modified: 2008-03-17
I am having trouble getting a report to preview/print correctly.  Since I haven't done Access programming in over a decade, I'm afraid my skills have slipped.  Here is what I have:  A combo box on a form selects an import date from a list, and then the form only displays the records that match the import date.  The Row Source property of the combo box is set as follows:  

SELECT tblPermitData.ImportDate FROM tblPermitData GROUP BY tblPermitData.ImportDate ORDER BY tblPermitData.ImportDate

After the date is selected, the user presses a button labeled 'Refresh', which has the On Click event set to:
Me.Requery

This all works fine and dandy.

So I put a button on the form for Print Preview, and created a report with the fields I want included.  But I can't figure out how to select only the data that is diplayed in the form.  Thanks in advance for any help.

Lew
0
Comment
Question by:lewhuskey
  • 4
5 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 16898036
Hi Lewhuskey,

If your data has a primary key uniquely identifying each record (I'll refer to it as ID), you can add a textbox to your form abd bind it to that ID field and call it txtID(you can set the textbox's visible property to "no" if you don't want it displayed).  

In the button that opens your report, use the following OpenReport statement:

Docmd.OpenReport "rptYourReportName", acViewPreview,, "ID = " & me.txtID
0
 
LVL 61

Expert Comment

by:mbizup
ID: 16898053
You would also need to include the ID in your select statement for the report's recordsource:

SELECT ID, tblPermitData.ImportDate FROM tblPermitData GROUP BY tblPermitData.ImportDate ORDER BY tblPermitData.ImportDate
             ^--- Add ID here

0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 16898071
Sorry... I misread a good portion of the question.  If you only want the report to display records based on the date... then change the openreport statement as follows:

Docmd.OpenReport "rptYourReportName", acViewPreview,, "ImportDate = #" & Me.txtImportDate & "#"

(and ignore my previous posts completely)
0
 

Author Comment

by:lewhuskey
ID: 16935600
Thanks, mbizup, that did it.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 16936740
Glad to help!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question