Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Preview a report from data in a form - Access 2003

Posted on 2006-06-13
5
Medium Priority
?
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

670 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