Results 1 to 6 of 6

Thread: printout (XP)

  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    printout (XP)

    I have the following code to open a report based on the filter and recordset of an open form (I got the code from somewhere, sorry do not remember where, probably here). My problem is that if I stop the code and show the report before the Docmd.Printout, i see only the filtered records on the report, but when it prints, it prints all the records on the report as if it is not filtered. Any Clues?

    Thanks

    DoCmd.Echo False
    rcdSource = Me.RecordSource
    strFilter = Me.Filter
    strOrder = Me.OrderBy
    DoCmd.OpenReport "rptaccount", acViewDesign

    Reports!rptaccount.RecordSource = rcdSource

    DoCmd.OpenReport "rptaccount", acPreview
    Reports!rptaccount.Text26.Value = Me.curStartBalance
    Reports!rptaccount.dtDateFrom.Value = Me.dtDateFrom
    Reports!rptaccount.dtDateTill.Value = Me.dtDateTill
    If Me.FilterOn = False Then

    Reports!rptaccount.OrderBy = strOrder
    Reports!rptaccount.OrderByOn = True
    Reports!rptaccount.FilterOn = False
    Else

    Reports!rptaccount.Filter = strFilter
    Reports!rptaccount.FilterOn = True
    Reports!rptaccount.OrderBy = strOrder
    Reports!rptaccount.OrderByOn = True
    End If
    DoCmd.Echo True
    DoCmd.PrintOut
    DoCmd.Close , , acSaveNo

    (I got sick of this project for a while and stopped thinking about Access. Does that ever happen to anyone else? <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35> )

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: printout (XP)

    I would put the code in the On Open event of the report. Let's say the form is named frmMyForm.

    Private Sub Report_Open()
    If CurrentProject.AllForms("frmMyForm").IsLoaded Then
    Me.RecordSource = Forms!frmMyForm.RecordSource
    If Forms!frmMyForm.FilterOn Then
    Me.Filter = Forms!frmMyForm.Filter
    Me.FilterOn = Forms!frmMyForm.FilterOn
    End If
    If Forms!frmMyForm.OrderByOn Then
    Me.OrderBy = Forms!frmMyForm.OrderBy
    Me.OrderByOn = Forms!frmMyForm.OrderByOn
    End If
    Me.Text26= Forms!frmMyForm.curStartBalance
    Me.dtDateFrom = Forms!frmMyForm.dtDateFrom
    Me.dtDateTill = Forms!frmMyForm.dtDateTill
    End If
    End Sub

    The code to print the report from frmMyForm becomes simply

    DoCmd.OpenReport "rptAccount", acViewNormal

    This is much cleaner, since you don't have to open the report in design view or preview in order to print it. If the form isn't open, the report will open as usual.

  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: printout (XP)

    As usual there is always a better way to do things and you enlighten us.
    Thanks

  4. #4
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: printout (XP)

    I only got around to checking this now, the first half works great setting the recordsource and filter, but i get the following error on the last three lines-"You cannot assign a value to this object Run time error 2147352567".
    I get that on the lines starting :
    Me.Text26 = Forms!frmaccount.curStartBalance
    'Me.dtDateFrom = Forms!frmaccount.dtDateFrom
    'Me.dtDateTill = Forms!frmaccount.dtDateTill
    Thanks

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: printout (XP)

    Assuming that the three controls are text boxes, try this:

    Me.Text26.ControlSource = "=Forms!frmaccount.curStartBalance"
    Me.dtDateFrom.ControlSource = "=Forms!frmaccount.dtDateFrom"
    Me.dtDateTill.ControlSource = "=Forms!frmaccount.dtDateTill"

    Another possibility is to use labels instead of text boxes. The code would become

    Me.Text26.Caption = Forms!frmaccount.curStartBalance
    Me.dtDateFrom.Caption = Forms!frmaccount.dtDateFrom
    Me.dtDateTill.Caption = Forms!frmaccount.dtDateTill

  6. #6
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: printout (XP)

    the first way worked. No reason to try the others since they already are text boxes. Thanks
    That is why in my original code I opened it in design view to get around this issue. But your way is more elegant

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •