Results 1 to 11 of 11
  1. #1
    alaric01 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    17

    change print preview record source

    hi i have form where user use it as an analytical form. every time a user set a certain criteria to the data, the form's record source change based on the criteria.

    in that form i've placed a print button that opens a report for that form. in onclick event of that button i've set the report's record source is equal to the form's record source.

    the problem occurs when i view the report in print preview. i've got an error message saying that record source cannot be change in print preview.



    any idea?

    thx

  2. #2
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    The way I handle this is to use DAO to modify the QueryDef of the Report's record source before opeinf then report.

    You could also try use the Report's On Open event to change the record source to match the form's record source.

    If you are applying a filter to the form, you can apply the form's filter to the report.

  3. #3
    alaric01 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    17
    thx for the reply.

    i am sorry i am a newbie in this access world, could you give an example of how to use DAO to modify the QueryDef?

    as for modifying the recordsource on open event i still got the same error, i've also tried on load event.

  4. #4
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by alaric01 View Post
    as for modifying the recordsource on open event i still got the same error, i've also tried on load event.
    On Load? Reports don't have an "On Load" event?

    So let's start with this:

    What is the name of the form?

    What is the code used to open the Report?

    Will you post the code you used in the On Open event?

  5. #5
    alaric01 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    17
    reports do have on load event..

    ok the form's name is frm_sales_report. in the form there's a button named btn_open_report_sales.

    and the report's name is rpt_sales_report

    in the onclick event of the button (in frm_sales_report) the code is:


    -----------------------------------
    'open the report
    DoCmd.OpenReport "rpt_sales_report", acViewReport, "", "", acNormal

    'modify the report's record source
    Reports!rpt_sales_report.RecordSource = Forms!frm_sales_report.Form.RecordSource

    Reports!rpt_sales_report.requery

    ------------------------------------

    when the report is open there's no problem, showing the same data as in the form. The problem only occurs when i view the report in print preview.

    i've tried to move that code to the on open and on load event of the report

    -------------

    Private Sub Report_Load()

    me.recordsource = Forms!frm_sales_report.form.RecordSource

    me.requery

    end sub

    -----------------

    still the same problem occurs when viewing in print preview

    oh yeah, also tried to open the report by using

    ---------------
    DoCmd.OpenReport "rpt_sales_report", acViewPreview, "", "", acNormal

    ---------------

    in the onclick event of the form's button. did not work.

  6. #6
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by alaric01 View Post
    reports do have on load event..
    My Bad. I did not see you were using 2007. I thought you were using 2002/2003.

    The On Load event for reports was added starting with 2007.

    I will give it a test with Access 2007

  7. #7
    alaric01 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    17
    thank you for the help, really appreciate it

    looking forward for your reply

  8. #8
    alaric01 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    17

    using filter instead

    ok i know how to get around it by using filter in the onload event of the report instead of changing the recordsource. i've got no more error message and the data displays correctly.

    However, i also have a label that suppose to display the date in the report and was chosen in the frm_sales_report. the date will show up in the report view. when i view in print preview the label shows nothing.

    here's my code now
    ------------
    Code:
    Private Sub Report_Load()
    
        If IsNull(Forms!frm_main_sales_report.txt_dari_tgl) Or _
        IsNull(Forms!frm_main_sales_report.txt_sampai_tgl) Then
    
        Me.txt_date_title.Value = ""
        Me.Filter = ""
        Me.FilterOn = False
        
        txt_jumlah_grand_total = Forms!frm_main_sales_report.txt_jumlah_grand_total.Value
        txt_total_pembayaran = Forms!frm_main_sales_report.txt_total_pembayaran.Value
        
        Else
        
        Me.Filter = "this is the filter criteria"
        Me.FilterOn = True
      
        Me.txt_date_title.Value = Forms!frm_main_sales_report.txt_dari_tgl & " - " & _
        Forms!frm_main_sales_report.txt_sampai_tgl
        
        txt_jumlah_grand_total = Forms!frm_main_sales_report.txt_jumlah_grand_total.Value
        txt_total_pembayaran = Forms!frm_main_sales_report.txt_total_pembayaran.Value
      
      End If
        
    End Sub
    -----------------------

    in print preview txt_date_title , txt_total_pembayaran and txt_jumlah_grand_total are blank. hopefully you're still following my thread HiTechCoach

  9. #9
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Still here.

    Since you are using Access 2007, do you have all the Office 2007 Service Packs install to at least SP2?

    Report View and Print Preview are very different. I generally never use the report view for reports I an designing to be printed.

    I have not ever trying your method of filtering. I usually have the the form that is collecting the criteria to pass the desired filter as a parameter of the Docmd.OpenReport. Another method I use is to modify the QueryDef() for the saved query for the report's record source before the report opens.

    On the report have you tried setting the control source for the text box txt_date_title to

    Code:
    =IIF(IsNull(Forms!frm_main_sales_report.txt_dari_tgl),"",Forms!frm_main_sales_report.txt_dari_tgl & " - " & Forms!frm_main_sales_report.txt_sampai_tgl )

  10. #10
    alaric01 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    17
    yes i think i have all the Office 2007 service pack installed.

    also tried the setting the control source to

    Code:
    =IIF(IsNull(Forms!frm_main_sales_report.txt_dari_tgl),"",Forms!frm_main_sales_report.txt_dari_tgl & " - " & Forms!frm_main_sales_report.txt_sampai_tgl )
    i don't understand. it's not about changing the recordsource or filtering anymore. cause even a simple vba code in the report such as

    Code:
    Me.txt_jumlah_grand_total = "test"
    will show up in the report view but not in the print preview

  11. #11
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Does it work if you print it out onto paper?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Print Preview Margins error
    By yes sir in forum Access
    Replies: 2
    Last Post: 09-15-2010, 05:52 PM
  2. Print preview with forms
    By jonesy29847 in forum Reports
    Replies: 4
    Last Post: 07-13-2010, 10:36 AM
  3. Can't see sub report in print preview
    By LoggyDoggy in forum Access
    Replies: 1
    Last Post: 04-20-2010, 05:38 PM
  4. Print Preview different from Print Hardcopy
    By peterc in forum Reports
    Replies: 4
    Last Post: 10-27-2009, 05:35 AM
  5. Error when trying to print or print preview
    By TriAdX in forum Reports
    Replies: 8
    Last Post: 08-25-2009, 08:20 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