Results 1 to 8 of 8
  1. #1
    Blings's Avatar
    Blings is offline Competent Performer
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    London, UK
    Posts
    125

    Despatch Notification

    Morning all,

    I'm trying to create a button that will on the onClick open up a new Outlook email with subject of Despatch | SO " & [SalesOrderNumber] and with a body of "Despatch Notification".

    Please can someone suggest code?



    Code:
    Private Sub cmdEmailProduction_Click()10        On Error GoTo cmdEmailProduction_Click_Error
    20            If Me.Dirty Then Me.Dirty = False
    '30      MsgBox "A Copy of the Production Order was saved to the Production Order Folder", vbInformation
          Dim strSQL As String
          Dim OutApp As Object
          Dim OutMail As Object
          Dim strToSQL As String
          Dim strSalesOrderNumber As String
         
          
          Dim strSubject As String
          Dim strMessage As String
          Dim strReportname As String
          Dim strPath As String
    
    
    35    strSalesOrderNumber = Me.SalesOrderNumber
    40    strToSQL = Me.txtEmail
    50    strSubject = "Despatch | SO " & [SalesOrderNumber] & ""
    60    strReportname = "rptSalesOrderProduction"
    70    strPath = "\\LUCREZIA-NOBLE\Database\ProductionOrders\" & "Production Order " & strSalesOrderNumber & ".pdf"
    
    
    
    
    80    DoCmd.OpenReport strReportname, acPreview, "", "[SalesOrderNumber]=[Forms]![frmSalesOrders].[Form]![SalesOrderNumber]"
    90    DoCmd.OutputTo acOutputReport, strReportname, acFormatPDF, "\\LUCREZIA-NOBLE\Database\ProductionOrders\" & "Production Order " & strSalesOrderNumber & ".pdf"
    
    
    
    
    100   strMessage = "Despatch Notification."
    
    
    110   Set OutApp = CreateObject("Outlook.Application")
    120   Set OutMail = OutApp.CreateItem(0)
    
    
    130   On Error Resume Next
    
    
    160   With OutMail
    170   .To = strToSQL
          '190     .CC = strCC1 & ";" & strCC2
    180     .Subject = strSubject
    190     .Attachments.Add strPath
    200     .Body = strMessage
    210       .Display
    220   End With
    
    
              
    230       On Error GoTo 0
    240       Exit Sub
    
    
    cmdEmailProduction_Click_Error:
    
    
    250       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdEmailProduction_Click, line " & Erl & "."
    
    
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    You have code. What happens - error message, wrong result, nothing?
    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
    Blings's Avatar
    Blings is offline Competent Performer
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    London, UK
    Posts
    125
    I want to strip the attachment from the email and only write an email.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    So why add it in the first place????
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Blings's Avatar
    Blings is offline Competent Performer
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    London, UK
    Posts
    125
    I copied and pasted from a different button that facilities that function hence my question why I asked.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    What do you mean by "it's a copy" - the code is a copy? If you don't want to do an attachment then remove the line or comment it.
    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.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Quote Originally Posted by June7 View Post
    What do you mean by "it's a copy" - the code is a copy? If you don't want to do an attachment then remove the line or comment it.
    I believe Blings is saying 'I have no idea what all this code does' ?

    Blings,
    You can probably get away with just this
    NB: Edited in Notepad++
    Personally I would also set any objects created to Nothing?

    Code:
    Private Sub cmdEmailProduction_Click()10        On Error GoTo cmdEmailProduction_Click_Error
    20            If Me.Dirty Then Me.Dirty = False
    
          Dim strSQL As String
          Dim OutApp As Object
          Dim OutMail As Object
          Dim strToSQL As String
          
          Dim strSubject As String
          Dim strMessage As String
          
    
    
    35    strSalesOrderNumber = Me.SalesOrderNumber
    40    strToSQL = Me.txtEmail
    50    strSubject = "Despatch | SO " & [SalesOrderNumber] & ""
    
    
    
    
    100   strMessage = "Despatch Notification."
    
    
    110   Set OutApp = CreateObject("Outlook.Application")
    120   Set OutMail = OutApp.CreateItem(0)
    
    
    130   On Error Resume Next
    
    
    160   With OutMail
    170   .To = strToSQL
    
    180     .Subject = strSubject
    
    200     .Body = strMessage
    210       .Display
    220   End With
    
    
              
    230       On Error GoTo 0
    240       Exit Sub
    
    
    cmdEmailProduction_Click_Error:
    
    
    250       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdEmailProduction_Click, line " & Erl & "."
    
    
    End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    Blings's Avatar
    Blings is offline Competent Performer
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    London, UK
    Posts
    125
    Thank you @Welshgasman. Your code worked perfectly

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

Similar Threads

  1. New thread notification?
    By projecttoday in forum Forum Suggestions
    Replies: 5
    Last Post: 11-06-2018, 02:43 PM
  2. Notification in access?
    By Xterra14s in forum Access
    Replies: 3
    Last Post: 08-09-2016, 03:59 PM
  3. Notification mail
    By patrokos in forum Queries
    Replies: 3
    Last Post: 01-26-2015, 01:11 PM
  4. Email Notification
    By Ariuser in forum Programming
    Replies: 1
    Last Post: 01-20-2012, 03:44 PM
  5. check box notification
    By nichmeg in forum Programming
    Replies: 6
    Last Post: 10-29-2011, 11:29 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