Note: This code can also be found in Help\Samples\Advanced Samples folder of your FE installation folder.
Add the following line to the APInvoice_AfterSave Event.
DoBigInvoiceEmail oRecord

Public Sub DoBigInvoiceEmail(oRecord As Object)
'Please note that a reference to the Microsoft Outlook 9.0 Object must be
'done in order for program to work
'All Invoices over $1,000 will fire an email to the CFO
'Todo Add who added the invoice

  Dim oAPInvoice As CAPInvoice
  On Error GoTo ErrHandler
  Set oAPInvoice = oRecord

  If oAPInvoice.Fields(APINVOICES_fld_INVOICEAMOUNT) > 1000 Then
      Dim oOutlook As Outlook.Application
      Set oOutlook = CreateObject("Outlook.Application")
      Dim oMailItem As MailItem
      Set oMailItem = oOutlook.CreateItem(olMailItem)

      oMailItem.To = ""
      oMailItem.Subject = "Big Invoice Alert"     

      Dim oApVendor As cAPVendor
      Set oApVendor = New cAPVendor
      oApVendor.Init goFE_Sessioncontext
      oApVendor.Load oAPInvoice.Fields(APINVOICES_fld_AP7VENDORSID), True
      Dim sTemp As String 

      sTemp = "An invoice for " & oApVendor.Fields(APVENDORS_fld_VENDORNAME_FORDISPLAY) & " has just been added in the amount of " & Format$(oAPInvoice.Fields(APINVOICES_fld_INVOICEAMOUNT), "currency") & "."
      sTemp = sTemp & "  The invoice description is '" & oAPInvoice.Fields(APINVOICES_fld_DESCRIPTION) & "'"

      oMailItem.Body = sTemp    
      oMailItem.Display    'Shows the Email, so user can see it
      'oMailItem.Send      'Sends the email without user intervention     

      Set oMailItem = Nothing
      Set oOutlook = Nothing     
      Set oApVendor = Nothing
  End If

  Set oAPInvoice = Nothing

  On Error GoTo 0
  Exit Sub

  Dim sErr As String
  sErr = Err.Description

  On Error GoTo 0
  '< place your custom error handling code here >
  MsgBox "Error processing DoBigInvoiceEmail : " & sErr

  If Not oApVendor Is Nothing Then
      Set oApVendor = Nothing
  End If 

  Set oAPInvoice = Nothing

End Sub

Disclaimer: We provide programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes you are familiar with Microsoft Visual Basic and the tools used to create and debug procedures. Our Customer Support can help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality. If you are interested in learning more about the VBA and API modules, contact your account manager.