Outlook Class

July 5, 2010

This is a simple class wrapper for creating/displaying Outlook email items with attachments:

Option Explicit

' MailItem CreateItem Type
Const olMailItem = 0        ' = Email

' Attachment Types
Const olByValue = 1         ' = By Value
Const olByReference = 4     ' = By Reference
Const olEmbeddedItem = 5    ' = Embedded Item

Class OutlookEmail
    Private objOE
    Private objMailItem
    Private objAttachments

    Private Sub Class_Initialize
        Set objOE = CreateObject("Outlook.Application")
        Set objMailItem = objOE.CreateItem(olMailItem)
        Set objAttachments = objMailItem.Attachments
    End Sub

    Private Sub Class_Terminate
        Set objAttachments = nothing
        Set objMailItem = nothing
        Set objOE = nothing
    End Sub

    Public Sub AddAttachment(FilePath, DisplayName)
        objAttachments.Add FilePath, olByValue, 1, DisplayName
    End Sub

    Public Sub Display()
        objMailItem.Display()
    End Sub
End Class

If you just have one attachment for the email, you could use Application.BasicFunctions.QueMessage instead: It will pop up your default email client, populated with whatever parameters you’ve passed.

Advertisements

Tips and Tricks – IV

May 20, 2010

Tips and Tricks IV: The Voyage Home.

  • SalesLogix performance will suffer with cursors being left open. If you are coding in SalesLogix it is very important that you close your Recordsets, setting your Recordsets to Nothing is NOT enough, you should always have code like this:
If oRS.State = 1 Then
    oRS.Close
End If
Set oRS = Nothing
' Need to restrict the Lookup to records where
' Account.Type='Customer' and Account.Location='US'):
LookUpName = "Account:Account"
RestrictAlways = True
Lookup.LookupRestrictField = "TYPE'"
Lookup.LookupRestrictOp = "='Customer' and LOCATION="
Lookup.LookupRestrictValue = "US"
  • Create a “.txt” file. Rename the file to “.udl”. When you double-click on the file it will display the standard connection designer!

And lots of good stuff from Ryan Farley’s site: