Results 1 to 4 of 4
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Trying to filter object subform

    I have button to print a report in a subform

    Code:
    
    Dim stDocName As String
    Dim com1 As Integer, com2 As Integer
    Dim MyForm As Form
    
    
    On Error GoTo errHandler
    stDocName = "rptPerformerDiary"
    com1 = Nz(Me.Text0, 0)
    com2 = Nz(Me.Text2, 0)
    
    
    Set MyForm = Screen.ActiveForm
    '
    'Forms(MyForm).PerformerDiaryPrint.Report.Filter = "[ShowYearID]=" & com1 & "  And [PerformersID] = " & com2
    'Forms(MyForm).PerformerDiaryPrint.Report.FilterOn = True
    
    
    DoCmd.SelectObject acReport, stDocName, True
    
    
    Application.RunCommand acCmdPrint
    DoCmd.SelectObject acForm, MyForm.Name, False
    
    
    errHandler:
     Select Case Err
     Case 2501
    MsgBox "You have cancelled printing"
    End Select
    Can't quite figure out how to filter the report first before printing (else it prints all the pages which is unfiltered).



    Help appreciated in advance

  2. #2
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I am using

    Code:
    If IsNull(Me.Text0) Or IsNull(Me.Text2) Then
    MsgBox "You need to choose a year and performer first"
    Else
    checkReportClosed ("rptPerformerDiary")
    Dim com1 As Integer, com2 As Integer
    
    
    On Error GoTo errHandler
    com1 = Nz(Me.Text0, 0)
    com2 = Nz(Me.Text2, 0)
    
    
    DoCmd.OpenReport "rptPerformerDiary", acViewPreview, , "[ShowYearID]=" & com1 & "  And [PerformersID] = " & com2
    Application.RunCommand acCmdPrint
    checkReportClosed ("rptPerformerDiary")
    
    
    errHandler:
     Select Case Err
     Case 2501
    MsgBox "You have cancelled printing"
    checkReportClosed ("rptPerformerDiary")
    
    
    End Select
    
    
    End If
    which works, however I was hoping the method in the first post would work too...

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Normally, the [showyearid] and [performersid] criteria would be in the query, thus eliminating any coding.
    This way you just docmd.openreport rpt, acviewpreview

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by ranman256 View Post
    Normally, the [showyearid] and [performersid] criteria would be in the query, thus eliminating any coding.
    This way you just docmd.openreport rpt, acviewpreview
    Yes but then that would restrict the report to that one situation - I may want to use the report more than once without having to recreate it, having a different button give a different action.

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

Similar Threads

  1. Replies: 13
    Last Post: 03-09-2014, 02:11 AM
  2. Replies: 1
    Last Post: 08-16-2012, 01:51 PM
  3. Replies: 6
    Last Post: 05-05-2012, 08:43 AM
  4. Pass Subform filter to subform in report
    By camftm in forum Programming
    Replies: 16
    Last Post: 07-19-2011, 07:12 AM
  5. Replies: 4
    Last Post: 07-07-2011, 03:21 PM

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