Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156

    filter for a report

    I need help with writing a filter code for a report ID number. I want to print a report based on the report ID number. The report name is "rptMonthlyCircleLog" I am lost on this one.

    Thanks



    Cheeco

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    What is 'report ID number'? ID number of what - customer, account, project?

    Whatever this ID number is for, select it from an UNBOUND combobox list or set focus to a record on form.

    Then code can open report filtered to that value like:

    DoCmd.OpenReport "rptMonthlyCircleLog", , , "ID=" & Me.cbxID

    Review http://allenbrowne.com/ser-62.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156
    I applied the filter to my Report and then went to set it up in the button control where is says apply filter then I get this

    Filter Name

    Where Condition

    Control Name

    I have no idea what these are oe what I am suppose to type in these boxes.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    What do you mean by 'applied the filter to my report'? Exactly what did you do?

    Set up the button how - with button wizard? Looks like it is opening macro builder.

    This is all basic Access functionality. Any introductory tutorial book should have guidance on this.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156
    I found this code for opening and emailing a report. Opening the form works fine however I keep getting a error with the line "Dim oApp As New Outlook.Application". The error message is " Compile Error, User-Defined type not defined" Any ideas.

    Code:
    Private Sub Command334_Click()    On Error GoTo ErrHandler
        DoCmd.OpenReport ReportName:="rptMonthlyCircleLog", View:=acViewPreview, _
            WhereCondition:="ID=" & Me.ID
        Exit Sub
    
    
    ErrHandler:
        ' Don't show error message if report was canceled
        If Err <> 2501 Then
            MsgBox Err.Description, vbCritical
        End If
        
       
    Dim oApp As New Outlook.Application
    Dim oEmail As Outlook.MailItem
    Dim fileName As String, todayDate As String
    
    
    'Export report in same folder as db with date stamp
    todayDate = Format(Date, "MMDDYYYY")
    fileName = Application.CurrentProject.path & "\rptMonthlyCircleLog_" & todayDate & ".pdf"
    DoCmd.OutputTo acReport, "rptMonthlyCircleLog", acFormatPDF, fileName, False
    
    
    'Email the results of the report generated
    Set oEmail = oApp.CreateItem(olMailItem)
    With oEmail
        .Recipients.Add "cheecochongo@outlook.com@email.com"
        .Subject = "Training Roster"
        .Body = "Roster Information"
        .Attachments.Add fileName
        .Send
    End With
    
    
    MsgBox "Email successfully sent!", vbInformation, "EMAIL STATUS"
    End Sub

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,129
    Add the VBA Outlook reference library for your Outlook version e.g. Microsoft Outlook 16.0 Object Library if using Outlook 2016
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Or maybe try the DoCmd.SendObject method. Don't need an Outlook object and therefore no Outlook library.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156
    I added the outlook library and now it is working but it is not filtering the report as it should. It is suppose to filter the report according to the report ID. But we are making progress. That is a good thing.

  9. #9
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Is ID a number? If not, you need single quotes before and after the variable part.

    For those who know more about vba, is this colon thing a valid construct that allows you to ignore the placeholders for comma separated parameters? I'm not used to seeing colon delimited parameters in DoCmd methods. The above is missing the FilterName parameter that normally you see between View and Where Condition when using commas.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156
    The id is a number

  11. #11
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Quote Originally Posted by CHEECO View Post
    The id is a number
    I see I missed that from #1. You're not getting a parameter prompt, so ID must be a field in the report's underlying query. Suggest you open the query in design view and put a valid ID number in the correct query field and run it. If you still get all records, then there is something amiss with the query for the report.

    Another test might be to put Msgbox Me.ID right after your on error line (there are other ways but they take longer to explain). If you get an empty message box, ID isn't being picked up (i.e. it is Null or an empty string).

  12. #12
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156
    OK I got it. The below code works great. Thanks for all the help.

    Code:
    Private Sub cmdEmail_Click()
    
    Dim oApp As New Outlook.Application
    Dim oEmail As Outlook.MailItem
    Dim fileName As String, todayDate As String
    
    
    'filter report
    'DoCmd.OpenReport "rptMonthlyCircleLog", , , "ID=" & Me.cbxID
    DoCmd.OpenReport "rptMonthlyCircleLog", acViewPreview, , "ID = " & ID
    
    
    
    
    'Export report in same folder as db with date stamp
    todayDate = Format(Date, "MMDDYYYY")
    fileName = Application.CurrentProject.path & "\rptMonthlyCircleLog_" & todayDate & ".pdf"
    DoCmd.OutputTo acReport, "rptMonthlyCircleLog", acFormatPDF, fileName, False
    
    
    'Email the results of the report generated
    Set oEmail = oApp.CreateItem(olMailItem)
    With oEmail
        .Recipients.Add "cheecochongo@outlook.com"
        .Subject = "Training Roster"
        .Body = "Roster Information"
        .Attachments.Add fileName
        .Send
    End With
    
    
    
    
     DoCmd.OpenReport ReportName:="rptMonthlyCircleLog", View:=acViewPreview, _
            WhereCondition:="ID=" & Me.ID
        Exit Sub
    
    
    
    
    ErrHandler:
        ' Don't show error message if report was canceled
        If Err <> 2501 Then
            MsgBox Err.Description, vbCritical
        End If
        
       
    
    
    MsgBox "Email successfully sent!", vbInformation, "EMAIL STATUS"
    End Sub

  13. #13
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Are we to assume the issue was using the colon syntax for your parameters? Or was it something else? The info might help someone else in the future.
    Thanks.

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Yes, I have seen the colon syntax. This is 'named arguments'. Allows not having to put the arguments in a specific order. Definitely works.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,129
    Quote Originally Posted by June7 View Post
    Yes, I have seen the colon syntax. This is 'named arguments'. Allows not having to put the arguments in a specific order. Definitely works.
    I'd never seen the point of the named arguments approach as its just extra typing.
    However, I wasn't aware that you could then do any order you like & presumably therefore omit unused items
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

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

Similar Threads

  1. Replies: 4
    Last Post: 04-30-2014, 09:40 PM
  2. Replies: 1
    Last Post: 07-25-2013, 01:20 PM
  3. Replies: 2
    Last Post: 05-10-2013, 03:37 PM
  4. how to filter the Report
    By ismailkhannasar in forum Reports
    Replies: 2
    Last Post: 02-05-2013, 07:41 PM
  5. Report Filter
    By SFC in forum Reports
    Replies: 4
    Last Post: 01-11-2012, 04:13 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