Link to home
Start Free TrialLog in
Avatar of lewhuskey
lewhuskeyFlag for United States of America

asked on

Preview a report from data in a form - Access 2003

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
Avatar of mbizup
mbizup
Flag of Kazakhstan image

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
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

ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lewhuskey

ASKER

Thanks, mbizup, that did it.
Glad to help!