Senin, 13 November 2017

Re: [MS_AccessPros] Filter report with vba

 

The SQL of qryReportASWRT should be changed with every record in RS_1. 


I would place a breakpoint in the code and step through it to make sure every line is being run.


Duane Hookom




From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Jim Wagner luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Monday, November 13, 2017 5:29 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Filter report with vba
 


the sql of the qryReportASWRT is

SELECT *
FROM qryReportsTo
WHERE (((qryReportsTo.SelectEmployee)=True));

Yes, I was hoping that I could get the report filtered on what users select in the table. I see what you are doing. with the code. I must be missing something.


Jim Wagner


On ‎Monday‎, ‎November‎ ‎13‎, ‎2017‎ ‎04‎:‎18‎:‎30‎ ‎PM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:


 

Jim,

The SQL should be an SQL statement, not vba. Please view the SQL of qryReportASWRT and report back. 


The code basically takes the current Supervisor and inserts them into the where clause of the report's record source. The report should then be filtered by the current supervisor which is what I thought you needed.


Duane Hookom



From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Jim Wagner luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Monday, November 13, 2017 5:10 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Filter report with vba
 


the source of the report is indeed qryReportASWRT

the sql section is

 ImmedSup = RS_1!ImmedSup 'the Supervisor is being renamed here. It originally is SupervisorName from the value that is in the Supervisor field from the strSQL above in the code, which is a list of all the supervisor name
    myFileName = myPath & "Accruals Report - " & ImmedSup & ".pdf" 'the SupervisorName is the value of the Supervisor field from the strSQL above in the code, which is a list of all the supervisors names
   
    ' Open the report with the filter and export it as PDF to the designated folder. Close the report.
     If Not IsNull(ImmedSup) Then

        strSQL2 = "SELECT * FROM qryReportsTo WHERE ImmedSup=""" & ImmedSup & """"

        'Change the report recordsource query to filter by ImmedSup

        strPrevSQL = fChangeSQL(strQueryName, strSQL2)

Debug.Print strSQL2   ' allows you to view the SQL statement

        DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport

        'DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport, , "ImmedSup=" & """" & ImmedSup & """", acNormal


        DoCmd.OutputTo acOutputReport, "rptAccrualSummaryWithReportsTo", "PDFFormat(*.pdf)", myFileName, False, "", 0, acExportQualityPrint

        DoCmd.Close acReport, "rptAccrualSummaryWithReportsTo"

    End If



Jim Wagner


On ‎Monday‎, ‎November‎ ‎13‎, ‎2017‎ ‎03‎:‎24‎:‎59‎ ‎PM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:


 

What is the record source of rptAccrualSummaryWithReportsTo and what is its SQL?


I would expect them to be:

Record Source: qryReportASWRT
SQL: "SELECT * FROM qryReportsTo WHERE ImmedSup="Some Immediate Supervisor value";

Regards,
Duane


From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Jim Wagner luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Monday, November 13, 2017 4:09 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Filter report with vba
 


Duane,

So I am still getting all of the records. It is not filtering the recordset. I chose 2 records to make it easier and the process emails every record.

Jim Wagner


On ‎Wednesday‎, ‎November‎ ‎8‎, ‎2017‎ ‎01‎:‎37‎:‎11‎ ‎PM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:


 

Hi Jim,


First you need to change the Dim of RW_1 which your code is not necessarily creating a DAO.Recordset

Dim RS_1 As DAO.Recordset, RS_2 As DAO.Recordset


I assume the record source of your report is qryReportASWRT.

Change the "strSQL" to "strSQL2" in the third line below and add a debug.print

   If Not IsNull(ImmedSup) Then

        strSQL2 = "SELECT * FROM qryReportsTo WHERE ImmedSup=""" & ImmedSup & """"

        'Change the report recordsource query to filter by ImmedSup

        strPrevSQL = fChangeSQL(strQueryName, strSQL2)

        debug.print strSQL2   ' allows you to view the SQL statement
        DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport

        'DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport, , "ImmedSup=" & """" & ImmedSup & """", acNormal


        DoCmd.OutputTo acOutputReport, "rptAccrualSummaryWithReportsTo", "PDFFormat(*.pdf)", myFileName, False, "", 0, acExportQualityPrint

        DoCmd.Close acReport, "rptAccrualSummaryWithReportsTo"

    End If


Duane Hookom
MN


From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Jim Wagner luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Wednesday, November 8, 2017 1:43 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Filter report with vba
 


Private Sub cmdEmailAccrualSummaryDirectReport_Click()

Dim db As DAO.Database

Set db = CurrentDb

Dim RS_1, RS_2 As DAO.Recordset

Dim strMsg As String

Dim ReportsToName, EmailAddress, SupervisorEmail, ImmedSup As String
Dim myPath, myFileName As String
Dim strSQL, strSQL1, strSQL2 As String

Dim objol As New Outlook.Application
Dim objmail As MailItem
Set objol = New Outlook.Application
Dim strQueryName As String
Dim strPrevSQL As String
Dim strSQL3 As String

 strQueryName = "qryReportASWRT"

DoCmd.SetWarnings False

strSQL = "SELECT DISTINCT Nz([Asc/Ast Dir],Nz([Dept Head],'Top Dog')) AS ImmedSup" _
& " FROM SupervisorTable INNER JOIN AccrualsForReport ON SupervisorTable.[Person Id] = AccrualsForReport.Emplid" _
& " WHERE (((SupervisorTable.[Person Id]) Not Like '1208509350'));"


' Open the record set containing all the supervisors
Set RS_1 = db.OpenRecordset(strSQL, dbOpenDynaset)
RS_1.MoveFirst

' Set the path to the folder which stores all the reports
myPath = "W:\ADMINISTRATIVE SERVICES DATABASES\MANAGEMENT SUPPORT SERVICES T-A-P\ABSENCE DATABASE\Department Reports\DirectReports\"


' For all entries, loop through, generate, store and email the report
Do While Not RS_1.EOF
 
    ' This routine is divided into two parts - 1) generate and store the report and 2) email the report
    ' We generate the report for all supervisors and store them in the designated folder.
    '**********************************************************************************************************************
    ' Section 1 - generate and store reports
    '**********************************************************************************************************************
  
    ' Obtain the supervisor's name
    ImmedSup = RS_1!ImmedSup 'the Supervisor is being renamed here. It originally is SupervisorName from the value that is in the Supervisor field from the strSQL above in the code, which is a list of all the supervisor name
    myFileName = myPath & "Accruals Report - " & ImmedSup & ".pdf" 'the SupervisorName is the value of the Supervisor field from the strSQL above in the code, which is a list of all the supervisors names
   
    ' Open the report with the filter and export it as PDF to the designated folder. Close the report.
     If Not IsNull(ImmedSup) Then

        strSQL2 = "SELECT * FROM qryReportsTo WHERE ImmedSup=""" & ImmedSup & """"

        'Change the report recordsource query to filter by ImmedSup

        strPrevSQL = fChangeSQL(strQueryName, strSQL)


        DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport

        'DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport, , "ImmedSup=" & """" & ImmedSup & """", acNormal


        DoCmd.OutputTo acOutputReport, "rptAccrualSummaryWithReportsTo", "PDFFormat(*.pdf)", myFileName, False, "", 0, acExportQualityPrint

        DoCmd.Close acReport, "rptAccrualSummaryWithReportsTo"

    End If
   
 
    '**********************************************************************************************************************
    ' Section 2 - Email reports
    '**********************************************************************************************************************
   
      ' Obtain the email address for the supervisor, set the subject and body accordingly
        ' Attach the report and send the mail.
       
    If Not IsNull(ImmedSup) Then
         strSQL1 = "SELECT [R&D-CURRENTEMPLOYEES].[Asu Email Addr] FROM [R&D-CURRENTEMPLOYEES] WHERE [R&D-CURRENTEMPLOYEES].[Person Nm]='" & ImmedSup & "'"
        Set RS_2 = db.OpenRecordset(strSQL1, dbOpenDynaset)
        RS_2.MoveFirst
        SupervisorEmail = RS_2![Asu Email Addr]
 
           
        Set objmail = objol.CreateItem(olMailItem)

        With objmail
       
        .BodyFormat = olFormatHTML
        .To = SupervisorEmail
        .Subject = "Accruals Report for  " & ImmedSup
        .HTMLBody = "Hello. Attached is your Direct Reports Accrual Summary Report. If you have any questions, please contact the Time and Attendance Team." _
        & vbCrLf & vbCrLf & _
        " - Thank You - " 'strMsg
        .NoAging = True


        .Attachments.Add myFileName
      
        .Display
        End With
        SendKeys "%{s}", True
    End If
RS_1.MoveNext
Loop
DoCmd.SetWarnings True

MsgBox "Reports have been emailed to the Direct Reports Employees."

End Sub





Module

Option Compare Database

Function fChangeSQL(pstrQueryName As String, strSQL As String) As String
'=============================================================
' basQueryDefs.ChangeSQL
'-------------------------------------------------------------
' Purpose : update the SQL property of a saved query
' Copyright: Duane Hookom
' Author : Duane Hookom
' Notes :
'-------------------------------------------------------------
' Parameters
'-----------
' pstrQueryName (String) Name of saved query
' strSQL (String)        SQL Statement
'-------------------------------------------------------------
' Returns: the previous SQL statement
'-------------------------------------------------------------
' Revision History
'-------------------------------------------------------------
' 07-09-2001 DKH:
'=============================================================
' End Code Header block
    Dim db As DAO.Database
    Dim qd As DAO.QueryDef
    Set db = CurrentDb
    Set qd = db.QueryDefs(pstrQueryName)
    fChangeSQL = qd.SQL
    qd.SQL = strSQL
    Set qd = Nothing
    Set db = Nothing
End Function



Jim Wagner


On ‎Wednesday‎, ‎November‎ ‎8‎, ‎2017‎ ‎12‎:‎22‎:‎16‎ ‎PM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:


 

Hi Jim,


Can you share your current code for the function as well as your cmdEmailAccrualSummaryDirectReport_Click?


Duane




From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Jim Wagner luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Wednesday, November 8, 2017 12:25 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Filter report with vba
 


Duane

I replaced the module code and I am still getting a ByRef argument type mismatch error. at the strSQL in the below line

strPrevSQL = fChangeSQL(strQueryName, strSQL)

Jim Wagner


On ‎Monday‎, ‎November‎ ‎6‎, ‎2017‎ ‎12‎:‎23‎:‎08‎ ‎PM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:


 

Hi Jim,

That function is old. I was thinking it was the one at http://www.tek-tips.com/faqs.cfm?fid=7433.


If you aren't using the function anywhere else in your application, you can replace the function with the one in the link.

www.tek-tips.com
There are times when the easiest method of creating complex queries with multiple filters is to change the SQL property of a saved query. This works well when you ...
Regards,
Duane Hookom



From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Jim Wagner luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Monday, November 6, 2017 11:29 AM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Filter report with vba
 


Duane

I am now getting a new error on

strPrevSQL = fChangeSQL(strQueryName, strSQL)

the message states the following

Compile error;
ByRef Argument Type mismatch


here is the module code

Function fChangeSQL(pstrQueryName As String, strQueryName As String, strSQL As String) As String
'=============================================================
' basQueryDefs.ChangeSQL
'-------------------------------------------------------------
' Purpose : update the SQL property of a saved query
' Copyright: Duane Hookom
' Author : Duane Hookom
' Notes :
'-------------------------------------------------------------
' Parameters
'-----------
' pstrQueryName (String) Name of saved query
' strSQL (String)        SQL Statement
'-------------------------------------------------------------
' Returns: the previous SQL statement
'-------------------------------------------------------------
' Revision History
'-------------------------------------------------------------
' 07-09-2001 DKH:
'=============================================================
' End Code Header block
    Dim db As DAO.Database
    Dim qd As DAO.QueryDef
    Set db = CurrentDb
    Set qd = db.QueryDefs(pstrQueryName)
    fChangeSQL = qd.SQL
    qd.SQL = strSQL
    Set qd = Nothing
    Set db = Nothing

End Function



Jim Wagner


On ‎Friday‎, ‎November‎ ‎3‎, ‎2017‎ ‎09‎:‎27‎:‎45‎ ‎PM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:


 

Jim,

You are setting the SQL property of a query to select from itself. This is like having [query1] with a SQL statement of "SELECT * FROM [Query1]". It's not possible in Access or possibly other query languages.


1) Create a new query named "qryReportASWRT" that has a sql statement of 

"SELECT * FROM qryReportsTo;"


2) Set the Recordsource of rptAccrualSummaryWithReportsTo to qryReportASWRT.


3) Change

        strQueryName = "qryReportsTo"

     to

         strQueryName = "qryReportASWRT"


 4) Try again


Regards,

Duane




From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Jim Wagner luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Friday, November 3, 2017 5:50 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Filter report with vba
 


 Here is the sub procedure below. It is crashing on the highlighted strSQL

Private Sub cmdEmailAccrualSummaryDirectReport_Click()

Dim db As DAO.Database

Set db = CurrentDb

Dim RS_1, RS_2 As DAO.Recordset

Dim strMsg As String

Dim ReportsToName, EmailAddress, SupervisorEmail, ImmedSup As String
Dim myPath, myFileName As String
Dim strSQL, strSQL1 As String

Dim objol As New Outlook.Application
Dim objmail As MailItem
Set objol = New Outlook.Application
Dim strQueryName As String
Dim strPrevSQL As String
Dim strSQL3 As String

strQueryName = "qryReportsTo"

DoCmd.SetWarnings False

strSQL = "SELECT DISTINCT Nz([Asc/Ast Dir],Nz([Dept Head],'Top Dog')) AS ImmedSup" _
& " FROM SupervisorTable INNER JOIN AccrualsForReport ON SupervisorTable.[Person Id] = AccrualsForReport.Emplid" _
& " WHERE (((SupervisorTable.[Person Id]) Not Like '1208509350'));"


' Open the record set containing all the supervisors
Set RS_1 = db.OpenRecordset(strSQL, dbOpenDynaset)
RS_1.MoveFirst

' Set the path to the folder which stores all the reports
myPath = "W:\ADMINISTRATIVE SERVICES DATABASES\MANAGEMENT SUPPORT SERVICES T-A-P\ABSENCE DATABASE\Department Reports\DirectReports\"


' For all entries, loop through, generate, store and email the report
Do While Not RS_1.EOF
 
    ' This routine is divided into two parts - 1) generate and store the report and 2) email the report
    ' We generate the report for all supervisors and store them in the designated folder.
    '**********************************************************************************************************************
    ' Section 1 - generate and store reports
    '**********************************************************************************************************************
  
    ' Obtain the supervisor's name
    ImmedSup = RS_1!ImmedSup 'the Supervisor is being renamed here. It originally is SupervisorName from the value that is in the Supervisor field from the strSQL above in the code, which is a list of all the supervisor name
    myFileName = myPath & "Accruals Report - " & ImmedSup & ".pdf" 'the SupervisorName is the value of the Supervisor field from the strSQL above in the code, which is a list of all the supervisors names
   
    ' Open the report with the filter and export it as PDF to the designated folder. Close the report.
     If Not IsNull(ImmedSup) Then

        strSQL = "SELECT * FROM qryReportsTo WHERE ImmedSup=""" & ImmedSup & """"

        'Change the report recordsource query to filter by ImmedSup

        strPrevSQL = fChangeSQL(strQueryName, strSQL)


        DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport

        'DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport, , "ImmedSup=" & """" & ImmedSup & """", acNormal


        DoCmd.OutputTo acOutputReport, "rptAccrualSummaryWithReportsTo", "PDFFormat(*.pdf)", myFileName, False, "", 0, acExportQualityPrint

        DoCmd.Close acReport, "rptAccrualSummaryWithReportsTo"

    End If
   
 
    '**********************************************************************************************************************
    ' Section 2 - Email reports
    '**********************************************************************************************************************
   
      ' Obtain the email address for the supervisor, set the subject and body accordingly
        ' Attach the report and send the mail.
       
    If Not IsNull(ImmedSup) Then
         strSQL1 = "SELECT [R&D-CURRENTEMPLOYEES].[Asu Email Addr] FROM [R&D-CURRENTEMPLOYEES] WHERE [R&D-CURRENTEMPLOYEES].[Person Nm]='" & ImmedSup & "'"
        Set RS_2 = db.OpenRecordset(strSQL1, dbOpenDynaset)
        RS_2.MoveFirst
        SupervisorEmail = RS_2![Asu Email Addr]
 
           
        Set objmail = objol.CreateItem(olMailItem)

        With objmail
       
        .BodyFormat = olFormatHTML
        .To = SupervisorEmail
        .Subject = "Accruals Report for  " & ImmedSup
        .HTMLBody = "Hello. Attached is your Direct Reports Accrual Summary Report. If you have any questions, please contact the Time and Attendance Team." _
        & vbCrLf & vbCrLf & _
        " - Thank You - " 'strMsg
        .NoAging = True


        .Attachments.Add myFileName
      
        .Display
        End With
        SendKeys "%{s}", True
    End If
RS_1.MoveNext
Loop
DoCmd.SetWarnings True

MsgBox "Reports have been emailed to the Direct Reports Employees."

End Sub



Jim Wagner


On ‎Friday‎, ‎November‎ ‎3‎, ‎2017‎ ‎12‎:‎43‎:‎48‎ ‎PM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:


 

In the sub


Dim strQueryName as String   'name of the saved query that is your report's record source
strQueryName = "qryReportsTo"
Do While Not RS_1.EOF

Duane


From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Jim Wagner luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Friday, November 3, 2017 2:29 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Filter report with vba
 


Duane

in the function or the sub procedure for the button

Jim Wagner


On ‎Friday‎, ‎November‎ ‎3‎, ‎2017‎ ‎12‎:‎18‎:‎42‎ ‎PM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:


 

Sorry, there should have been another line to use strQueryName. Place this line anywhere after the Dims.


strQueryName = "qryReportsTo"


Regards,
Duane


From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Jim Wagner luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Friday, November 3, 2017 12:48 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Filter report with vba
 


I am getting a compile error
Variable not defined

strPrevSQL = fChangeSQL(qryReportsTo, strSQL)

Jim Wagner


On ‎Thursday‎, ‎November‎ ‎2‎, ‎2017‎ ‎09‎:‎23‎:‎50‎ ‎PM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:


 

Jim,

Try:


' For all entries, loop through, generate, store and email the report
' this code depends on having the function fChangeSQL() in a standard module in your Access file
Dim strSQL as String
Dim strPrevSQL as String
Dim strQueryName as String   'name of the saved query that is your report's record source

Do While Not RS_1.EOF
 
    ' This routine is divided into two parts - 1) generate and store the report and 2) email the report
    ' We generate the report for all supervisors and store them in the designated folder.
    '**********************************************************************************************************************
    ' Section 1 - generate and store reports
    '**********************************************************************************************************************
   
    ' Obtain the supervisor's name
    ImmedSup = RS_1!ImmedSup 'the Supervisor is being renamed here. _
                              It originally is SupervisorName from _
                              the value that is in the Supervisor _
                              field from the strSQL above in the code, _
                              which is a list of all the supervisor name
    myFileName = myPath & "Accruals Report - " & ImmedSup & ".pdf" 
                             'the SupervisorName is the value of the Supervisor field _
                              from the strSQL above in the code, _
                              which is a list of all the supervisors names
    
    ' Open the report with the filter and export it as PDF to the designated folder. Close the report.
    If Not IsNull(ImmedSup) Then
        strSQL = "SELECT * FROM YourBaseQuery WHERE ImmedSup=""" & ImmedSup & """"
        'Change the report recordsource query to filter by ImmedSup
        strPrevSQL = fChangeSQL(strQueryName, strSQL)  

        DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport
        'DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport, , "ImmedSup=" & """" & ImmedSup & """", acNormal

        DoCmd.OutputTo acOutputReport, "rptAccrualSummaryWithReportsTo", "PDFFormat(*.pdf)", myFileName, False, "", 0, acExportQualityPrint
        DoCmd.Close acReport, "rptAccrualSummaryWithReportsTo"
    End If

Duane Hookom

MN




From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Jim Wagner luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Thursday, November 2, 2017 5:18 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Filter report with vba
 


Duane

thank you. I am not sure how to implement that into my code to open the report with that filter I need

' For all entries, loop through, generate, store and email the report
Do While Not RS_1.EOF
 
    ' This routine is divided into two parts - 1) generate and store the report and 2) email the report
    ' We generate the report for all supervisors and store them in the designated folder.
    '**********************************************************************************************************************
    ' Section 1 - generate and store reports
    '**********************************************************************************************************************
  
    ' Obtain the supervisor's name
    ImmedSup = RS_1!ImmedSup 'the Supervisor is being renamed here. It originally is SupervisorName from the value that is in the Supervisor field from the strSQL above in the code, which is a list of all the supervisor name
    myFileName = myPath & "Accruals Report - " & ImmedSup & ".pdf" 'the SupervisorName is the value of the Supervisor field from the strSQL above in the code, which is a list of all the supervisors names
   
    ' Open the report with the filter and export it as PDF to the designated folder. Close the report.
    If Not IsNull(ImmedSup) Then
        'DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport
        DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport, "", "ImmedSup=" & """" & ImmedSup & """", acNormal
        'DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport, , "ImmedSup=" & """" & ImmedSup & """", acNormal

        DoCmd.OutputTo acOutputReport, "rptAccrualSummaryWithReportsTo", "PDFFormat(*.pdf)", myFileName, False, "", 0, acExportQualityPrint
        DoCmd.Close acReport, "rptAccrualSummaryWithReportsTo"
    End If





Jim Wagner


On ‎Thursday‎, ‎November‎ ‎2‎, ‎2017‎ ‎02‎:‎24‎:‎47‎ ‎PM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:


 

Jim,


I actually prefer to change the SQL of the query that is the report's record source. I use a little DAO code as described on this Tek-Tips FAQ http://www.tek-tips.com/faqs.cfm?fid=7433


Duane

www.tek-tips.com
There are times when the easiest method of creating complex queries with multiple filters is to change the SQL property of a saved query. This works well when you ...




From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Jim Wagner luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Thursday, November 2, 2017 1:26 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Filter report with vba
 


Duane

the report still wants to do all of the employees. I only selected 2 employees and it emailed all of them.



Jim Wagner


On ‎Thursday‎, ‎November‎ ‎2‎, ‎2017‎ ‎11‎:‎20‎:‎01‎ ‎AM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:


 

Jim,


What happens if you get rid of the first 

DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport


Regards,

Duane Hookom

MN




From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Thursday, November 2, 2017 1:14 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] Filter report with vba
 


Hello all,


I am trying to filter a report in VBA. The user wants to limit the records being emailed out for an Accruals report. The user wants to select the employees in a table. Then the report is to be emailed to the supervisors. So I have the following code to open the report. The user will open the table and click a Yes/No check box and then I need the report to use the SelectEmployee field to be used to exclude employees with the check box selected. I have tried to add the filter on the docmd.openreport line but it never filters the report.


Thank You for any help.

Jim Wagner


 ImmedSup = RS_1!ImmedSup 'the Supervisor is being renamed here. It originally is SupervisorName from the value that is in the Supervisor field from the strSQL above in the code, which is a list of all the supervisor name
    myFileName = myPath & "Accruals Report - " & ImmedSup & ".pdf" 'the SupervisorName is the value of the Supervisor field from the strSQL above in the code, which is a list of all the supervisors names
   
    ' Open the report with the filter and export it as PDF to the designated folder. Close the report.
    If Not IsNull(ImmedSup) Then
        DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport
        DoCmd.OpenReport "rptAccrualSummaryWithReportsTo", acViewReport, "", "ImmedSup=" & """" & ImmedSup & """", acNormal

        DoCmd.OutputTo acOutputReport, "rptAccrualSummaryWithReportsTo", "PDFFormat(*.pdf)", myFileName, False, "", 0, acExportQualityPrint
        DoCmd.Close acReport, "rptAccrualSummaryWithReportsTo"
    End If

























__._,_.___

Posted by: Duane Hookom <duanehookom@hotmail.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (25)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar