Emailing various Reports (via CMD button) from an Option Group

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ladybug76
    New Member
    • Mar 2008
    • 13

    #1

    Emailing various Reports (via CMD button) from an Option Group

    Hello.

    Okay, so I have an Option Group with 6 reports on the Right hand side of a form. On the left, I have 4 command buttons. 1) Preview 2) Print 3) Save off 4) Email.

    I want the user to be able to select a report's radio button and click one of the four command buttons. Currently, Preview and Print work. But the Reports have parameters in their queries. I'm prompted for the values for the Print and Preview buttons, but for some reason, I can not get the Email command button to work.

    I also don't know where to start for saving the report to a network drive. I'm assuming I'll run into the same error.

    (Error: Argument not Optional)

    Here's the code I have so far. Any ideas??
    THANKS A MILLION!

    Code:
    Sub PrintReports(PrintMode As Integer)
        On Error GoTo Err_Preview_Click
            'This procedure used in Preview_Click and Print_Click Sub procedure.
            'Preview or print report selected in the SelectReports option group.
            'Then close the Select Reports Dialog Form.
        
        Select Case Me!SelectReports
            Case 1
                DoCmd.OpenReport "R_Reasonableness", PrintMode
            Case 2
                DoCmd.OpenReport "R_ADJ", PrintMode
            Case 3
                DoCmd.OpenReport "R_Detail", PrintMode
            Case 4
                DoCmd.OpenReport "R_Detail2", PrintMode
            Case 5
                DoCmd.OpenReport "R_Summary", PrintMode
            Case 6
                DoCmd.OpenReport "R_Summary2", PrintMode
        End Select
        DoCmd.Close acForm, "F_REPORTS"
        
    Exit_Preview_Click:
        Exit Sub
        
    Err_Preview_Click:
        Resume Exit_Preview_Click
            
    End Sub
    
    Private Sub Email_Click()
    'E-Mail selected report. This procedure uses the PrintReports
    'Sub procedure defined in (General) section of this module.
     
        DoCmd.SendObject acReport, PrintReports, "RichTextFormat(*.rtf)", "", "email@email.com", "", "MfrReb Report", "This email is being sent from the MR Database", True, ""
        
    End Sub
    
    Private Sub Print_Click()
    'Print selected report. This procedure uses the PrintReports
    'Sub procedure defined in (General) section of this module.
    
        PrintReports acNormal
    End Sub
    
    Private Sub Preview_Click()
    'Preview selected report. This procedure uses the PrintReports
    'Sub procedure defined in (General) section of this module.
    
        PrintReports acPreview
        
    End Sub
  • puppydogbuddy
    Recognized Expert Top Contributor
    • May 2007
    • 1923

    #2
    I think you have several syntax errors in your SendObject statement. Try it this way:

    DoCmd.SendObjec t acSendReport, PrintReports, acFormatRTF," ","email@email. com"," ", "MfrReb Report", "This email is being sent from the MR Database", True

    Comment

    • ladybug76
      New Member
      • Mar 2008
      • 13

      #3
      Hi PuppydogBuddy.

      First and foremost, thanks for your guidance. It is extremely appreciated!!!!
      Now, back to busines... :)

      I tried replacing my DoCmd.SendObjec ts line with your suggestion and I'm still getting the same error. When I put your code in the immediate window, I got a Runtime error 2487.

      You wouldn't happen to know any other tricks, work arounds or other suggestions to get this working, would you? :) I know I can have the user just select "Email report" from the Preview window, but I was hoping to not have to go that route.

      Thank you again for your assistance.
      ~Bug

      Comment

      • puppydogbuddy
        Recognized Expert Top Contributor
        • May 2007
        • 1923

        #4
        I will look into this further, but here is something I just noticed that may resolve your problem. The error you were getting was "Argument Not Optional". I just notice that your procedure: Sub PrintReports(Pr intMode As Integer) requires that you pass PrintMode to the PrintReports procedure. In your SendObject statement you referenced PrintReports, but do not pass PrintMode to the referenced procedure. That is why you are getting the error.

        Comment

        • puppydogbuddy
          Recognized Expert Top Contributor
          • May 2007
          • 1923

          #5
          PS: forgot to tell you that an argument can be omitted from a call to a user-defined procedure if it was declared Optional in the procedure declaration. See this link:

          Comment

          • ladybug76
            New Member
            • Mar 2008
            • 13

            #6
            I also had to tweak the original call from a sub to a function and make the PrintMode Optional. But I finally got it to work

            THANK YOU THANK YOU THANK YOU!!!

            I've said it before, I'll say it again.. thescripts ROCK!!!!!!!!!!! !!!


            Here's the code in case anyone else ever runs into this again:


            Code:
            (vb)
            
            Option Compare Database    'Use database order for string comparisions.
            Option Explicit 'Requires variables to be declared before they are used
            
            
            Function PrintReports(Optional PrintMode As Integer)
                On Error GoTo Err_Preview_Click
                    'This procedure used in Preview, Print, Save and Email Click Sub procedures.
                    'Preview, Print, Save or Email report selected in the SelectReports option group.
                    'Then close the Select Reports Dialog Form.
                
                Select Case Me!SelectReports
                    Case 1
                        PrintReports = "R_Reasonableness"
                    Case 2
                        PrintReports = "R_Adjustments"
                    Case 3
                        PrintReports = "R_Detail"
                    Case 4
                        PrintReports = "R_PrePaidBalance"
                    Case 5
                        PrintReports = "R_Paid"
                    
                End Select
                'DoCmd.Close acForm, "F_REPORTS"
                
            Exit_Preview_Click:
                Exit Function
                
            Err_Preview_Click:
                Resume Exit_Preview_Click
                    
            End Function
            
            
            
            Private Sub Cmd_Save_Click()
            'Save selected report. This procedure uses the PrintReports
            'Function procedure defined in (General) section of this module.
                
                  DoCmd.OutputTo acReport, PrintReports, acFormatRTF, "C:\NetworkFoldersHere\" & PrintReports & ".rtf", True
            End Sub
            
            
            Private Sub Email_Click()
            
            'E-Mail selected report. This procedure uses the PrintReports
            'Function procedure defined in (General) section of this module.
             
             
                 DoCmd.SendObject acSendReport, PrintReports(), acFormatRTF, "email@email.com", , , "Report: " & PrintReports, "This email is being sent from the MR Database", True
            End Sub
            
            
            Private Sub Print_Click()
            'Print selected report. This procedure uses the PrintReports
            'Function procedure defined in (General) section of this module.
            
                DoCmd.OpenReport PrintReports, acNormal
            End Sub
            
            Private Sub Preview_Click()
            'Preview selected report. This procedure uses the PrintReports
            'Function procedure defined in (General) section of this module.
            
                DoCmd.OpenReport PrintReports, acPreview
                
            End Sub
            
            
            Private Sub Close_Click()
            DoCmd.Close
            End Sub

            Comment

            • puppydogbuddy
              Recognized Expert Top Contributor
              • May 2007
              • 1923

              #7
              Bug,
              You are most welcome. Glad we could help you resolve your problem. Thanks for posting the final solution.

              PDB

              Comment

              Working...