[AccessD] Automating Outlook - clsEmails

John Colby jwcolby at gmail.com
Sat Aug 21 08:57:07 CDT 2021


Not sure if I sent this to AccessD

On Sat, Aug 21, 2021 at 9:55 AM John Colby <jwcolby at gmail.com> wrote:

> I use a plural / singular naming convention when I will potentially have
> multiple instances of an object.  clsEmails (plural) is the email
> "supervisor", it is directly handed the email from outlook, creates an
> instance of clsEmail (singular) and passes the Email object off to it to be
> saved into a table.  The idea is that this class has a collection for
> storing all the clsEmail (singular) instances.   This class can also read
> all the emails out of the email table for future processing, creating
> instances of each record and storing them in the collection.  Thus I can
> come at emails from two directions, the email being received from Outlook
> and stored in the table, or the records in tblEmail.
>
> Option Compare Database
> Option Explicit
>
> Dim mcolEmails As Collection
> Dim mColEMInitialOrder As Collection
>
> Private Sub Class_Initialize()
>     Set mcolEmails = New Collection
>     Set mColEMInitialOrder = New Collection
> End Sub
> Private Sub Class_Terminate()
>     Set mcolEmails = Nothing
>     Set mColEMInitialOrder = Nothing
> End Sub
>
> ' ----------------------------------------------------------------
> ' Procedure Name: fEmailRcvd
> ' Purpose: Tests whether this is an email to be processed
> ' Procedure Kind: Function
> ' Procedure Access: Public
> ' Parameter item (Object): Email object still in object form
> ' Return Type: Boolean
> ' Author: John Colby
> ' Date: 7/30/2021
> ' ----------------------------------------------------------------
> Function fEmailRcvd(item As Object) As Boolean
>     On Error GoTo fEmailRcvd_Error
> Dim lclsEMail As clsEMail
> Dim lclsEmailANPurchase As clsEMailANPurchase
>     '
>     'The subject has to have something we recognize in order to filter out
> spam
>     'and emails not related to processing Advisor notes stuff
>     '
>     If InStr(item.Subject, "Order Entered") Or _
>         InStr(item.Subject, "Order Processed") _
>     Then
>     'If InStr(item.Subject, "AN Initial Order") Then
>         Debug.Print "This email is an order" & vbCrLf & vbCrLf
>         '
>         'This stores the email information
>         'There may eventually be many types of emails created from
>         'Whatever is contained in this email's body
>         '
>         'for now I am just processing orders
>         '
>         Set lclsEMail = New clsEMail    'This class processes the actual
> email coming in
>         lclsEMail.mInit item
>         'lclsEMail.fStoreEmail item      'Pass the email object in to it
>         mcolEmails.Add lclsEMail
>         '
>         'This processes the actual order, extracting the order info
>         '
>         Set lclsEmailANPurchase = New clsEMailANPurchase
>         lclsEmailANPurchase.fInit lclsEMail.pBody, lclsEMail.pSubject
>         mColEMInitialOrder.Add lclsEmailANPurchase
>
>         fEmailRcvd = True   'Tell the caller that this was an email of
> interest
>     End If
>
>
> Exit_fEmailRcvd:
>     On Error GoTo 0
>     Exit Function
>
> fEmailRcvd_Error:
> Dim strErrMsg As String
>     Select Case Err
>     Case 0      'insert Errors you wish to ignore here
>         Resume Next
>     Case Else   'All other errors will trap
>         strErrMsg = "Error " & Err.Number & " (" & Err.Description & ") in
> procedure Advisor Notes Administration.clsEmails.fEmailRcvd, line " & Erl &
> "."
>         Beep
> #If boolELE = 1 Then
>         WriteErrorLog strErrMsg
> #End If
>         assDebugPrint strErrMsg
>         Resume Exit_fEmailRcvd
>     End Select
>     Resume Exit_fEmailRcvd
>     Resume 0    'FOR TROUBLESHOOTING
> End Function
>
>
>
>
> --
> John W. Colby
> Colby Consulting
>


-- 
John W. Colby
Colby Consulting


More information about the AccessD mailing list