Runtime Error 2487

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DJRhino1175
    New Member
    • Aug 2017
    • 221

    Runtime Error 2487

    I'm getting runtime Error 2487: The object Type argument for the action or method is blank or invalid

    It triggers at line 36

    I have been using this code for awhile, but all of a sudden it stopped working. Can anyone see something I have wrong?

    Code:
    Private Sub btnAuditEmail_Click()
    
        On Error GoTo Error
        
        Dim strEMail        As String
        Dim strSubject      As String
        Dim strBody         As String
        Dim MyDB            As DAO.Database
        Dim rstEMail        As DAO.Recordset
        Dim strReportName   As String
        Dim myReportWhere   As String
        Dim myOutPutFile    As String
        Dim aFile           As String
        Dim strAtch         As String
        Dim strMsg          As String
     
            
            strMsg = "No Reject Tag Number. Please fill out the whole Reject Tag. Then try to resend"
            
            strReportName = _
                Replace(Replace("REJECT TAG#|1 PN |2", "|1", Nz(" " & _
                [REJECT TAG NUMBER], " ")), "|2", Nz([Part Number] & _
                " " & [Descriptive Reason], " "))
                
            myReportWhere = "[REJECT TAG NUMBER] = [Forms]![Reject Tag Form Edit]![REJECT TAG NUMBER]"
     
            DoCmd.OpenReport _
                ReportName:="Reject Tag Report", _
                View:=acViewPreview, _
                WhereCondition:=myReportWhere, _
                WindowMode:=acWindowNormal
     
            myOutPutFile = "M:\Inspect\New Reject Tag Database\Reports" & _
                "\" & strReportName & ".PDF"
     
            DoCmd.OutputTo _
                Objecttype:=acOutputReport, _
                Outputformat:=acFormatPDF, _
                Outputfile:=myOutPutFile, _
                AutoStart:=False, _
                Outputquality:=acExportQualityPrint
     
            DoCmd.Close _
                Objecttype:=acReport, _
                ObjectName:="Reject Tag Report", _
                Save:=acSaveNo
     
    
            'Retrieve all E-Mail Addressess in tblEMail4
            
    Set MyDB = CurrentDb
    Set rstEMail = MyDB.OpenRecordset("Select * From tblEMail4", _
                    dbOpenSnapshot, dbOpenForwardOnly)
     
    With rstEMail
      Do While Not .EOF
      
        'Build the Recipients String
        strEMail = strEMail & ![EmailAddress] & ";"
          .MoveNext
      Loop
    End With
            Call MyDB.Close
            Set rstEMail = Nothing
            Set MyDB = Nothing
     
            strBody = _
                "Please review the attached Reject Tag."
            strSubject = _
                Replace(Replace("REJECT TAG#|1 PN |2", "|1", Nz(" " & _
                [REJECT TAG NUMBER], " ")), "|2", Nz([Part Number] & _
                " " & [Descriptive Reason], " "))
            strAtch = _
                "M:\Inspect\New Reject Tag Database\Reports" & _
                "\" & strReportName & ".PDF"
     
               Call SendAnEmail(olSendTo:=strEMail, _
                             olSubject:=strSubject, _
                             olEMailBody:=strBody, _
                             olAtchs:=strAtch, _
                             olDisplay:=True, _
                             SendAsHTML:=True)
     
            aFile = _
                "M:\Inspect\New Reject Tag Database\Reports" & _
                "\" & strReportName & ".PDF"
            If Len(Dir$(aFile)) > 0 Then _
                 Call Kill(PathName:=aFile)
        
    Error:
       MsgBox strMsg, vbCritical, "No Reject Tag number"
       Exit Sub
    End Sub
  • isladogs
    Recognized Expert Moderator Contributor
    • Jul 2007
    • 479

    #2
    Hi
    Apologies that your post ended up in the moderation queue and that there was a delay in approving it.
    Hopefully it will be answered soon

    Comment

    • DJRhino1175
      New Member
      • Aug 2017
      • 221

      #3
      I ended up figuring it out...Thanks

      Comment

      • isladogs
        Recognized Expert Moderator Contributor
        • Jul 2007
        • 479

        #4
        Congratulations .
        It may be helpful to others if you could explain what your solution was.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          Hi DJ.

          I assume you found that one of the values you passed as a parameter was invalid for that command. Can you confirm?

          Comment

          • DJRhino1175
            New Member
            • Aug 2017
            • 221

            #6
            That would be my guess. I just kept tinkering till it just decided to work. I believe it was in my filter somewhere.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              Hi DJ.

              Frustrating, but I absolutely know what you mean :-D

              Great that it's sorted anyway.

              Comment

              Working...