Results 1 to 10 of 10
  1. #1
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481

    Sending email of current record report via outllook


    Hi,

    Is it correct code for sending email from a form of current record data via outlook.


    Code:
    Private Sub cmdemail_Click()On Error GoTo Err_cmdemail_Click
     
        Dim stDocName As String
        Dim strDocName As String
        Dim stWhere As String
        Dim stEmail As String
        Dim stSubject As String
     
        If Me.Dirty Then Me.Dirty = False
     
        stDocName = "Quality Inspection Report"
        strWhere = "[InspectionID]=" & Me!InspectionID
        stEmail = "zahid@cpc.com.sa"
        stSubject = "VCP Finish Goods Quality Inspection Report"
     
        DoCmd.SendObject acSendForm, stDocName, acFormatPDF, stEmail, , , stSubject, , , False
     
    Exit_cmdemail_Click:
        Exit Sub
     
    Err_cmdemail_Click:
        MsgBox Err.Description
        Resume Exit_cmdemail_Click
    End Sub
    but it shows error on click "The database cant find the object 'l1'

    Kindly help

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    your doc name is 'QI report'
    but your .SendObject says : acSendForm

    are you sending a report or a form? (reports are better)
    if this is not a problem, then check the vb references in VBE,(ctl-G), menu, tools, references,
    make sure MS OUTLOOK is checkmarked. (and not MISSING)

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The Outlook reference wouldn't be required for that code, and could cause problems if the db were used by someone with a different version.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    What does the strWhere line do in the code above?

  5. #5
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    Dear

    Thanks for correction and it was out of mind.

    Code:
    Private Sub cmdemail_Click()
    On Error GoTo Err_cmdemail_Click
     
        Dim stDocName As String
        Dim strDocName As String
        Dim stWhere As String
        Dim stEmail As String
        Dim stSubject As String
     
        If Me.Dirty Then Me.Dirty = False
     
        stDocName = "Quality Inspection Report"
        strWhere = "[InspectionID]=" & Me!InspectionID
        stEmail = "zahid@cpc.com.sa"
        stSubject = "VCP Finish Goods Quality Inspection Report"
     
        DoCmd.SendObject acSendReport, stDocName, acFormatPDF, stEmail, , , stSubject, , , False
     
    Exit_cmdemail_Click:
        Exit Sub
     
    Err_cmdemail_Click:
        MsgBox Err.Description
        Resume Exit_cmdemail_Click
    End Sub

    This code worked fantastic but cant restrict to the current record of report. It will fetch all the previous records too.

    but it worked the same way as "EmailDataBaseObject" macro which does not have criteria to restrict up to the current record.

    Kindly advise.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Simplist is probably to open the report in preview mode using strWhere, then send, then close the report. You can open it hidden to avoid the flicker of it opening.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    Again if anyone can answer, how is that strWhere clause being used in that code? I must be missing something obvious?

  8. #8
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    It isn't being used at all, and .SendObject doesn't have a where clause, therefore Paul's suggestion in post #6

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I noticed the declaration of stWhere but setting of strWhere and suggest:

    http://www.baldyweb.com/OptionExplicit.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    Ok thanks, just thought i was missing how it was being used somehow.

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

Similar Threads

  1. Email a report of the current record.
    By jonudden in forum Reports
    Replies: 4
    Last Post: 08-21-2023, 07:37 AM
  2. Sending a Report by Email
    By Robert2150 in forum Programming
    Replies: 3
    Last Post: 10-25-2014, 11:14 PM
  3. Email sending, Record Saving and Error Handling.
    By abodi in forum Programming
    Replies: 6
    Last Post: 08-31-2014, 05:28 PM
  4. Replies: 6
    Last Post: 11-07-2013, 04:02 PM
  5. Sending A Report Via Email
    By Ka-Tet in forum Reports
    Replies: 0
    Last Post: 09-02-2013, 09:18 AM

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