Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    keiath is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    162

    Printing a report from form in view


    How do i only produce so that i can view/print only from the form in view? Once I press a button to generate the report

    Thanks

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Do not totally understand the objective. What do you want to do with the report, print, save to PDF file, email? You do not want the report to show on the screen, only the form that causes the event to be viewed by the user?

  3. #3
    keiath is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    162
    I want it show on screen, then user can print as needed,

    But I only want it to show the form that is currently open.

    ie:- if i run the report now it has all 269 records what i want is just the report for the record I have open and reviewing.

    Hope that makes sense

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Does not really make sense but I will guess that you want to open a report in print preview from a form using the forms filtered recordset.

    If your report is based on the same query object as your form, the following should work. (untested)

    Code:
    Dim strfilter As String
    strfilter = ""
    If Me.FilterOn = True Then
    strfilter = Me.Filter
    End If
    DoCmd.OpenReport "ReportName", acViewPreview, , strfilter, acWindowNormal

  5. #5
    keiath is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    162
    i am not sure how this would work, as i have a button on the form to open the report,

    say I am looking at Site Number 0272S i want to click the button it opens the report in Print Preview only for 0272S.

    Currently if I click the button it will open report in print view but it doesnt filter and the page i see is the first record which is 0001S, which means i have to then click and find the one i actually want.

    Hope that makes more sense

    Thanks again for yourt help

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The example I showed you is VBA. It belongs in an event procedure that handles a given event, like On Click. You can create an event handler by going to the Event tab in the properties sheet, for a given control, and clicking the ellipses(...) next to the event you desire. Be sure to first clear out any text regarding an Embedded Macro before creating the VBA event handler.


    Clicking the ellipses will open a window, select "Code Builder". This will launch the VBA Editor and give you a place to write your code.

    The code sample depends on the form's filter to then filter the report as it opens.

    You can pass criteria to the Docmd.Open report. The example uses the form’s filter property as the criteria. You do not have to use the form's filter criteria. You can pass any criteria you wish.

  7. #7
    keiath is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    162
    this line

    DoCmd.OpenReport(Front,acViewPreview,strfilter,acW indowNormal)

    is coming up with a compile error = Expected

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The name of the report is Front?

    So maybe
    Code:
    DoCmd.OpenReport "Front", acViewPreview, , strfilter, acWindowNormal

  9. #9
    keiath is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    162
    Yes "Front" is the name of the report.

    I tried what you said that now opens the report, but the information is missing?

    Only the typed woprding is there (ie the part that not tried to anything) and the data that should be there is missing

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I just tested the code in Post#4 and it worked for me. Form's filter on, report returns filtered results. Form's filter off, report returns all results.

    Does your report share the same Query/Table as its recordsource? The same recordsource as the form?

  11. #11
    keiath is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    162
    I have looked at the button properties and I cant see a filter to switch on

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Regardless of whether or not the form's filter is turned on or not, your report should open and display, at least, some records. I would address that issue first by verifying the recordsource of the report.

    Then you can apply filters to your form using the intrinsic filter tools. Perhaps right clicking in a field will help.

    I provided the code guessing that you are filtering records in a form as you view them. You need to tell the report which records you want to view and pass that criteria to the Docmd.OpenReport.

  13. #13
    keiath is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    162
    So I added this

    Private Sub Command594_Click()
    Dim strfilter As String
    strfilter = ""
    If Me.FilterOn = True Then
    strfilter = Me.Filter
    End If
    DoCmd.OpenReport "Front", acViewPreview
    End Sub

    this shows all the data but for all the forms. so there is something not working on the filter part, when i add the filter , strfilter, acWindowNormal to the end of that line the data is missing again

    The filter element is simply the actual form in view which as the Site Code as its primary key

  14. #14
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    That was not the behavior I got this morning when I tested the code.

    Are you trying to filter the report to a single record? You can pass that argument directly to the Docmd. What is the name of the field that is the Primary Key?

  15. #15
    keiath is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    162
    yeah all i want to do is open a REPORT of the form that i currently have open.

    otherwise i will have 2000 pages of the report and then i have to work out what page the report i want to print it

    The primary key is SITE NUMBER

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Printing report from Form
    By cotri in forum Access
    Replies: 8
    Last Post: 05-24-2013, 12:01 PM
  2. Replies: 8
    Last Post: 04-29-2013, 11:23 AM
  3. Printing a report in a navigation form
    By DanKoz in forum Forms
    Replies: 2
    Last Post: 08-29-2011, 12:11 PM
  4. Printing a single report from form
    By OFA in forum Forms
    Replies: 9
    Last Post: 06-08-2010, 09:27 AM
  5. Replies: 16
    Last Post: 06-03-2009, 07:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums