Solved

Sending mail via Access

Posted on 2002-06-21
8
672 Views
Last Modified: 2007-12-19
Hi !
I have developet a archive-system in Access for looking up and communication with any object locally or globally.

One of these objects is mail, making it possible to send
e-mail to adresses not contained in the adress-book in a wery fast manner.

After having converted to Windows-2000 this has become a
problem.
The statement in question is the following:

DoCmd.SendObject , , , <Adress>, , , <Subject>,<Message>, True

It works the first time, but seems to be locked after that

Is there a setting in Outlook or somewhere to solve the problem ?

Jan
0
Comment
Question by:skyberg
8 Comments
 
LVL 4

Expert Comment

by:Nevaar
ID: 7098528
What do you mean by "seems to be locked"?  What happens (or doesn't happen)?
0
 

Expert Comment

by:manuelac
ID: 7098663
You may want to check out this link http://www.tek-tips.com/gviewthread.cfm/lev2/4/lev3/27/pid/181/qid/49081 as it offers you a solution or check the MS kb Q260819 - ACC2000: SendObject Method Fails in Access 2000 where this problem is detailed.
0
 

Author Comment

by:skyberg
ID: 7103955
Hi Nevaar !
By saying "seem to be locked" I mean that nothing happens
when I perform the statement mentioned above the second
time. The first time, the Outlook-form opens nicely for
keying in the text. When I close the Access-app and open
again, the statement works OK.

Jan
0
 

Author Comment

by:skyberg
ID: 7116068
Hi manuelac !
The item You refers to on Tek-tips, suggests there is
some upper limit in number of characters in the message.
In my case, the number is far below 100 chars.
In my system, the SendObject opens up for manual input.
It is therefore only the mail-adress, a fixed subject and
some openning phrases that is automated.
The rest is keyed inn manually.
When I mail myself, it works ok the first time.
The second time, nothing happens.

Jan
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Expert Comment

by:manuelac
ID: 7116713
Hi Skyberg

Unfortunately that's all I could find on the net. We are having the same problem with one of our db running on A2K, the SendObject works once only, then it silently fails. Only by exiting the application and relaunching again we get it to work again 1 more time! If you find a solution please let me know. Thanks.
0
 

Author Comment

by:skyberg
ID: 7121223
I will.
I keep the case open until futher.

Jan
0
 
LVL 28

Accepted Solution

by:
TextReport earned 50 total points
ID: 7229571
skyberg, I always use MAPI code to do mailing rather then send object, MAPI allows you to attach files other than those generated by the sendobject. The code I use originated frm an MS KB article from yearts back but still workd with Access 2000 and Outlook 2000.

Paste the code below in a new module.

Cheers, Andrew
Option Compare Database
Option Explicit

'------------------------------------------------------------------------
'
'    MAPI32.TXT -- MAPI32 API Declarations for Visual Basic
'
'              Copyright (C) 1994 Microsoft Corporation
'
'
'  This file contains only the Const, Type,
'  and Declare statements for  MAPI32 APIs.
'
'  You have a royalty-free right to use, modify, reproduce and distribute
'  this file (and/or any modified version) in any way you find useful,
'  provided that you agree that Microsoft has no warranty, obligation or
'  liability for its contents.
'
'------------------------------------------------------------------------

'***************************************************
'   MAPI Message holds information about a message
'***************************************************

Private Type MAPIMessage
    reserved As Long
    Subject As String
    NoteText As String
    MessageType As String
    DateReceived As String
    ConversationID As String
    Flags As Long
    RecipCount As Long
    FileCount As Long
End Type


'************************************************
'   MAPIRecip holds information about a message
'   originator or recipient
'************************************************

Private Type MAPIRecip
    reserved As Long
    RecipClass As Long
    Name As String
    Address As String
    EIDSize As Long
    EntryID As String
End Type


'******************************************************
'   MapiFile holds information about file attachments
'******************************************************

Private Type MAPIFile
    reserved As Long
    Flags As Long
    Position As Long
    PathName As String
    filename As String
    FileType As String
End Type


'***************************
'   FUNCTION Declarations
'***************************

Private Declare Function MAPILogon Lib "MAPI32.DLL" (ByVal UIParam&, ByVal User$, ByVal Password$, _
                                             ByVal Flags&, ByVal reserved&, Session& _
                                            ) As Long
Private Declare Function MAPILogoff Lib "MAPI32.DLL" (ByVal Session&, ByVal UIParam&, ByVal Flags&, ByVal reserved&) As Long
Private Declare Function BMAPIReadMail Lib "MAPI32.DLL" (lMsg&, nRecipients&, nFiles&, ByVal Session&, _
                                                 ByVal UIParam&, MessageID$, ByVal Flag&, ByVal reserved& _
                                                ) As Long
Private Declare Function BMAPIGetReadMail Lib "MAPI32.DLL" (ByVal lMsg&, Message As MAPIMessage, _
                                                    Recip() As MAPIRecip, File() As MAPIFile, _
                                                    Originator As MAPIRecip _
                                                   ) As Long
Private Declare Function MAPIFindNext Lib "MAPI32.DLL" Alias "BMAPIFindNext" (ByVal Session&, ByVal UIParam&, _
                                                                      MsgType$, SeedMsgID$, ByVal Flag&, _
                                                                      ByVal reserved&, MsgID$ _
                                                                     ) As Long
Private Declare Function MAPISendDocuments Lib "MAPI32.DLL" (ByVal UIParam&, ByVal DelimStr$, ByVal FilePaths$, _
                                                     ByVal FileNames$, ByVal reserved& _
                                                    ) As Long
Private Declare Function MAPIDeleteMail Lib "MAPI32.DLL" (ByVal Session&, ByVal UIParam&, ByVal MsgID$, ByVal Flags&, ByVal reserved&) As Long
Private Declare Function MAPISendMail Lib "MAPI32.DLL" Alias "BMAPISendMail" (ByVal Session&, ByVal UIParam&, Message As MAPIMessage, Recipient() As MAPIRecip, File() As MAPIFile, ByVal Flags&, ByVal reserved&) As Long
Private Declare Function MAPISaveMail Lib "MAPI32.DLL" Alias "BMAPISaveMail" (ByVal Session&, ByVal UIParam&, Message As MAPIMessage, Recipient() As MAPIRecip, File() As MAPIFile, ByVal Flags&, ByVal reserved&, MsgID$) As Long
Private Declare Function BMAPIAddress Lib "MAPI32.DLL" (lInfo&, ByVal Session&, ByVal UIParam&, Caption$, ByVal nEditFields&, Label$, nRecipients&, Recip() As MAPIRecip, ByVal Flags&, ByVal reserved&) As Long
Private Declare Function BMAPIGetAddress Lib "MAPI32.DLL" (ByVal lInfo&, ByVal nRecipients&, Recipients() As MAPIRecip) As Long
Private Declare Function MAPIDetails Lib "MAPI32.DLL" Alias "BMAPIDetails" (ByVal Session&, ByVal UIParam&, Recipient As MAPIRecip, ByVal Flags&, ByVal reserved&) As Long
Private Declare Function MAPIResolveName Lib "MAPI32.DLL" Alias "BMAPIResolveName" (ByVal Session&, ByVal UIParam&, ByVal username$, ByVal Flags&, ByVal reserved&, Recipient As MAPIRecip) As Long



'**************************
'   CONSTANT Declarations
'**************************
'

Const SUCCESS_SUCCESS = 0
Const MAPI_USER_ABORT = 1
Const MAPI_E_USER_ABORT = MAPI_USER_ABORT
Const MAPI_E_FAILURE = 2
Const MAPI_E_LOGIN_FAILURE = 3
Const MAPI_E_LOGON_FAILURE = MAPI_E_LOGIN_FAILURE
Const MAPI_E_DISK_FULL = 4
Const MAPI_E_INSUFFICIENT_MEMORY = 5
Const MAPI_E_BLK_TOO_SMALL = 6
Const MAPI_E_TOO_MANY_SESSIONS = 8
Const MAPI_E_TOO_MANY_FILES = 9
Const MAPI_E_TOO_MANY_RECIPIENTS = 10
Const MAPI_E_ATTACHMENT_NOT_FOUND = 11
Const MAPI_E_ATTACHMENT_OPEN_FAILURE = 12
Const MAPI_E_ATTACHMENT_WRITE_FAILURE = 13
Const MAPI_E_UNKNOWN_RECIPIENT = 14
Const MAPI_E_BAD_RECIPTYPE = 15
Const MAPI_E_NO_MESSAGES = 16
Const MAPI_E_INVALID_MESSAGE = 17
Const MAPI_E_TEXT_TOO_LARGE = 18
Const MAPI_E_INVALID_SESSION = 19
Const MAPI_E_TYPE_NOT_SUPPORTED = 20
Const MAPI_E_AMBIGUOUS_RECIPIENT = 21
Const MAPI_E_AMBIG_RECIP = MAPI_E_AMBIGUOUS_RECIPIENT
Const MAPI_E_MESSAGE_IN_USE = 22
Const MAPI_E_NETWORK_FAILURE = 23
Const MAPI_E_INVALID_EDITFIELDS = 24
Const MAPI_E_INVALID_RECIPS = 25
Const MAPI_E_NOT_SUPPORTED = 26

Const MAPI_ORIG = 0
Const MAPI_TO = 1
Const MAPI_CC = 2
Const MAPI_BCC = 3

Const MAPI_W_NO_SERVICE = 262659
Const MAPI_W_ERRORS_RETURNED = 263040
Const MAPI_W_POSITION_CHANGED = 263297
Const MAPI_W_APPROX_COUNT = 263298
Const MAPI_W_CANCEL_MESSAGE = 263552
Const MAPI_W_PARTIAL_COMPLETION = 263808

Const MAPI_E_INTERFACE_NOT_SUPPORTED = -2147467262
Const MAPI_E_CALL_FAILED = -2147467259
Const MAPI_E_NO_SUPPORT = -2147221246
Const MAPI_E_BAD_CHARWIDTH = -2147221245
Const MAPI_E_STRING_TOO_LONG = -2147221243
Const MAPI_E_UNKNOWN_FLAGS = -2147221242
Const MAPI_E_INVALID_ENTRYID = -2147221241
Const MAPI_E_INVALID_OBJECT = -2147221240
Const MAPI_E_OBJECT_CHANGED = -2147221239
Const MAPI_E_OBJECT_DELETED = -2147221238
Const MAPI_E_BUSY = -2147221237
Const MAPI_E_NOT_ENOUGH_DISK = -2147221235
Const MAPI_E_NOT_ENOUGH_RESOURCES = -2147221234
Const MAPI_E_NOT_FOUND = -2147221233
Const MAPI_E_VERSION = -2147221232
Const MAPI_E_LOGON_FAILED = -2147221231
Const MAPI_E_SESSION_LIMIT = -2147221230
Const MAPI_E_USER_CANCEL = -2147221229
Const MAPI_E_UNABLE_TO_ABORT = -2147221228
Const MAPI_E_NETWORK_ERROR = -2147221227
Const MAPI_E_DISK_ERROR = -2147221226
Const MAPI_E_TOO_COMPLEX = -2147221225
Const MAPI_E_BAD_COLUMN = -2147221224
Const MAPI_E_EXTENDED_ERROR = -2147221223
Const MAPI_E_COMPUTED = -2147221222
Const MAPI_E_CORRUPT_DATA = -2147221221
Const MAPI_E_UNCONFIGURED = -2147221220
Const MAPI_E_FAILONEPROVIDER = -2147221219
Const MAPI_E_UNKNOWN_CPID = -2147221218
Const MAPI_E_UNKNOWN_LCID = -2147221217
Const MAPI_E_PASSWORD_CHANGE_REQUIRED = -2147221216
Const MAPI_E_PASSWORD_EXPIRED = -2147221215
Const MAPI_E_INVALID_WORKSTATION_ACCOUNT = -2147221214
Const MAPI_E_INVALID_ACCESS_TIME = -2147221213
Const MAPI_E_ACCOUNT_DISABLED = -2147221212
Const MAPI_E_END_OF_SESSION = -2147220992
Const MAPI_E_UNKNOWN_ENTRYID = -2147220991
Const MAPI_E_MISSING_REQUIRED_COLUMN = -2147220990
Const MAPI_E_BAD_VALUE = -2147220735
Const MAPI_E_INVALID_TYPE = -2147220734
Const MAPI_E_TYPE_NO_SUPPORT = -2147220733
Const MAPI_E_UNEXPECTED_TYPE = -2147220732
Const MAPI_E_TOO_BIG = -2147220731
Const MAPI_E_DECLINE_COPY = -2147220730
Const MAPI_E_UNEXPECTED_ID = -2147220729
Const MAPI_E_UNABLE_TO_COMPLETE = -2147220480
Const MAPI_E_TIMEOUT = -2147220479
Const MAPI_E_TABLE_EMPTY = -2147220478
Const MAPI_E_TABLE_TOO_BIG = -2147220477
Const MAPI_E_INVALID_BOOKMARK = -2147220475
Const MAPI_E_WAIT = -2147220224
Const MAPI_E_CANCEL = -2147220223
Const MAPI_E_NOT_ME = -2147220222
Const MAPI_E_CORRUPT_STORE = -2147219968
Const MAPI_E_NOT_IN_QUEUE = -2147219967
Const MAPI_E_NO_SUPPRESS = -2147219966
Const MAPI_E_COLLISION = -2147219964
Const MAPI_E_NOT_INITIALIZED = -2147219963
Const MAPI_E_NON_STANDARD = -2147219962
Const MAPI_E_NO_RECIPIENTS = -2147219961
Const MAPI_E_SUBMITTED = -2147219960
Const MAPI_E_HAS_FOLDERS = -2147219959
Const MAPI_E_HAS_MESSAGES = -2147219958
Const MAPI_E_FOLDER_CYCLE = -2147219957
Const MAPI_E_AMBIGUOUS_RECIP = -2147219712
Const MAPI_E_INVALID_PARAMETER = -2147024809
Const MAPI_E_NOT_ENOUGH_MEMORY = -2147024882
Const MAPI_E_NO_ACCESS = -2147024891


'***********************
'   FLAG Declarations
'***********************

'* MAPILogon() flags *

Const MAPI_LOGON_UI = &H1
Const MAPI_NEW_SESSION = &H2
Const MAPI_FORCE_DOWNLOAD = &H1000

'* MAPILogoff() flags *

Const MAPI_LOGOFF_SHARED = &H1
Const MAPI_LOGOFF_UI = &H2

'* MAPISendMail() flags *

Const MAPI_DIALOG = &H8

'* MAPIFindNext() flags *

Const MAPI_UNREAD_ONLY = &H20
Const MAPI_GUARANTEE_FIFO = &H100

'* MAPIReadMail() flags *

Const MAPI_ENVELOPE_ONLY = &H40
Const MAPI_PEEK = &H80
Const MAPI_BODY_AS_FILE = &H200
Const MAPI_SUPPRESS_ATTACH = &H800

'* MAPIDetails() flags *

Const MAPI_AB_NOMODIFY = &H400

'* Attachment flags *

Const MAPI_OLE = &H1
Const MAPI_OLE_STATIC = &H2

'* MapiMessage flags *

Const MAPI_UNREAD = &H1
Const MAPI_RECEIPT_REQUESTED = &H2
Const MAPI_SENT = &H4

'*************************************************************
' FUNCTION NAME: TextReport_SendMail
'
' PURPOSE:
'   This is the front-end function to the MAPISendMail function. You
'   pass a semicolon-delimited list of To and CC recipients, a
'   subject, a message, and a delimited list of file attachments.
'   This function prepares MapiRecip and MapiFile structures with the
'   data parsed from the information provided using the ParseRecord
'   sub. Once the structures are prepared, the MAPISendMail function
'   is called to send the message.
'
' INPUT PARAMETERS:
'   sSubject: The text to appear in the subject line of the message
'   sTo:      Semicolon-delimited list of names to receive the
'             message
'   sCC:      Semicolon-delimited list of names to be CC'd

'   sAttach:  Semicolon-delimited list of files to attach to
'             the message
' RETURN
'   SUCCESS_SUCCESS if successful, or a MAPI error if not.

'*********************************************************** **
Function TextReport_SendMail(sSubject As String, sTo As String, sCC As String, sAttach As String, sMessage As String, Optional pbooSilent As Boolean)
Dim i, cTo, cCC, cAttach          ' variables holding counts
Dim booSilent As Boolean
Dim lngSendMail As Long
Dim strMsg As String

Dim MAPI_Message As MAPIMessage

    If IsMissing(pbooSilent) Then
       booSilent = False
    Else
       booSilent = pbooSilent
    End If
   
    ' Count the number of items in each piece of the mail message
    cTo = CountTokens(sTo, ";")
    cCC = CountTokens(sCC, ";")
    cAttach = CountTokens(sAttach, ";")

    ' Create arrays to store the semicolon delimited mailing
    ' .. information after it is parsed
    ReDim rTo(0 To cTo) As String
    ReDim rCC(0 To cCC) As String
    ReDim rAttach(0 To cAttach) As String
    ' Parse the semicolon delimited information into the arrays.
    ParseTokens rTo(), sTo, ";"
    ParseTokens rCC(), sCC, ";"
    ParseTokens rAttach(), sAttach, ";"

    ' Create the MAPI Recip structure to store all the To and CC
    ' .. information to be passed to the MAPISendMail function
    ReDim MAPI_Recip(0 To cTo + cCC - 1) As MAPIRecip


    ' Setup the "TO:" recipient structures
    For i = 0 To cTo - 1
        MAPI_Recip(i).Name = rTo(i)
        MAPI_Recip(i).RecipClass = MAPI_TO
    Next i

    ' Setup the "CC:" recipient structures
    For i = 0 To cCC - 1
        MAPI_Recip(cTo + i).Name = rCC(i)
        MAPI_Recip(cTo + i).RecipClass = MAPI_CC
    Next i
 
    ' Create the MAPI File structure to store all the file attachment
    ' .. information to be passed to the MAPISendMail function
    ReDim MAPI_File(0 To cAttach) As MAPIFile

    ' Setup the file attachment structures
    MAPI_Message.FileCount = cAttach
    For i = 0 To cAttach - 1
        MAPI_File(i).Position = -1
        MAPI_File(i).PathName = rAttach(i)
    Next i

    ' Set the mail message fields
    MAPI_Message.Subject = sSubject
    MAPI_Message.NoteText = sMessage
    MAPI_Message.RecipCount = cTo + cCC


    ' Send the mail message
   
    lngSendMail = MAPISendMail(0&, 0&, MAPI_Message, MAPI_Recip(), MAPI_File(), MAPI_LOGON_UI, 0&)
   
    If Not booSilent Then
       Select Case lngSendMail
           Case SUCCESS_SUCCESS
           Case MAPI_USER_ABORT: strMsg = "The User Aborted the Message"
           Case MAPI_E_FAILURE: strMsg = "MAPI Failure"
           Case MAPI_E_LOGIN_FAILURE: strMsg = "MAPI Login Failure"
           Case MAPI_E_DISK_FULL: strMsg = "Disk Full"
           Case MAPI_E_INSUFFICIENT_MEMORY: strMsg = "Insufficient Memory """
           Case MAPI_E_BLK_TOO_SMALL: strMsg = "MAPI Block Too Small"
           Case MAPI_E_TOO_MANY_SESSIONS: strMsg = "MAPI Too Many Sessions """
           Case MAPI_E_TOO_MANY_FILES: strMsg = "MAPI Too Many Files"
           Case MAPI_E_TOO_MANY_RECIPIENTS: strMsg = "MAPI Too Many Recipients """
           Case MAPI_E_ATTACHMENT_NOT_FOUND: strMsg = "MAPI Attachment Not Found"
           Case MAPI_E_ATTACHMENT_OPEN_FAILURE: strMsg = "MAPI Unable To Open Attachment"
           Case MAPI_E_ATTACHMENT_WRITE_FAILURE: strMsg = "MAPI Attachment Write Failure"
           Case MAPI_E_UNKNOWN_RECIPIENT: strMsg = "MAPI Unknown Recipient """
           Case MAPI_E_BAD_RECIPTYPE: strMsg = "MAPI Bad Recipient Type"
           Case MAPI_E_NO_MESSAGES: strMsg = "MAPI No Messages"
           Case MAPI_E_INVALID_MESSAGE: strMsg = "MAPI Invalid Message"
           Case MAPI_E_TEXT_TOO_LARGE: strMsg = "MAPI Text Too Large"
           Case MAPI_E_INVALID_SESSION: strMsg = "MAPI Invalid Session"
           Case MAPI_E_TYPE_NOT_SUPPORTED: strMsg = "MAPI Type Not Supported"
           Case MAPI_E_AMBIGUOUS_RECIPIENT: strMsg = "MAPI Ambiguous Recipient"
           Case MAPI_E_MESSAGE_IN_USE: strMsg = "MAPI Message In Use"
           Case MAPI_E_NETWORK_FAILURE: strMsg = "MAPI Network Failure"
           Case MAPI_E_INVALID_EDITFIELDS: strMsg = "MAPI Invalid EditFields"
           Case MAPI_E_INVALID_RECIPS: strMsg = "MAPI Invalid Recips"
           Case MAPI_E_NOT_SUPPORTED: strMsg = "MAPI Not Supported"
           
           Case MAPI_W_NO_SERVICE: strMsg = "MAPI_W_NO_SERVICE"
           Case MAPI_W_ERRORS_RETURNED: strMsg = "MAPI_W_ERRORS_RETURNED"
           Case MAPI_W_POSITION_CHANGED: strMsg = "MAPI_W_POSITION_CHANGED"
           Case MAPI_W_APPROX_COUNT: strMsg = "MAPI_W_APPROX_COUNT"
           Case MAPI_W_CANCEL_MESSAGE: strMsg = "MAPI_W_CANCEL_MESSAGE"
           Case MAPI_W_PARTIAL_COMPLETION: strMsg = "MAPI_W_PARTIAL_COMPLETION"
           
           Case MAPI_E_PASSWORD_EXPIRED: strMsg = "MAPI_E_PASSWORD_EXPIRED"
           Case MAPI_E_INVALID_WORKSTATION_ACCOUNT: strMsg = "MAPI_E_INVALID_WORKSTATION_ACCOUNT"
           Case MAPI_E_INVALID_ACCESS_TIME: strMsg = "MAPI_E_INVALID_ACCESS_TIME"
           Case MAPI_E_ACCOUNT_DISABLED: strMsg = "MAPI_E_ACCOUNT_DISABLED"
           Case MAPI_E_END_OF_SESSION: strMsg = "MAPI_E_END_OF_SESSION"
           Case MAPI_E_UNKNOWN_ENTRYID: strMsg = "MAPI_E_UNKNOWN_ENTRYID"
           Case MAPI_E_MISSING_REQUIRED_COLUMN: strMsg = "MAPI_E_MISSING_REQUIRED_COLUMN"
           Case MAPI_E_BAD_VALUE: strMsg = "MAPI_E_BAD_VALUE"
           Case MAPI_E_INVALID_TYPE: strMsg = "MAPI_E_INVALID_TYPE"
           Case MAPI_E_TYPE_NO_SUPPORT: strMsg = "MAPI_E_TYPE_NO_SUPPORT"
           Case MAPI_E_UNEXPECTED_TYPE: strMsg = "MAPI_E_UNEXPECTED_TYPE"
           Case MAPI_E_TOO_BIG: strMsg = "MAPI_E_TOO_BIG"
           Case MAPI_E_DECLINE_COPY: strMsg = "MAPI_E_DECLINE_COPY"
           Case MAPI_E_UNEXPECTED_ID: strMsg = "MAPI_E_UNEXPECTED_ID"
           Case MAPI_E_UNABLE_TO_COMPLETE: strMsg = "MAPI_E_UNABLE_TO_COMPLETE"
           Case MAPI_E_TIMEOUT: strMsg = "MAPI_E_TIMEOUT"
           Case MAPI_E_TABLE_EMPTY: strMsg = "MAPI_E_TABLE_EMPTY"
           Case MAPI_E_TABLE_TOO_BIG: strMsg = "MAPI_E_TABLE_TOO_BIG"
           Case MAPI_E_INVALID_BOOKMARK: strMsg = "MAPI_E_INVALID_BOOKMARK"
           Case MAPI_E_WAIT: strMsg = "MAPI_E_WAIT"
           Case MAPI_E_CANCEL: strMsg = "MAPI_E_CANCEL"
           Case MAPI_E_NOT_ME: strMsg = "MAPI_E_NOT_ME"
           Case MAPI_E_CORRUPT_STORE: strMsg = "MAPI_E_CORRUPT_STORE"
           Case MAPI_E_NOT_IN_QUEUE: strMsg = "MAPI_E_NOT_IN_QUEUE"
           Case MAPI_E_NO_SUPPRESS: strMsg = "MAPI_E_NO_SUPPRESS"
           Case MAPI_E_COLLISION: strMsg = "MAPI_E_COLLISION"
           Case MAPI_E_NOT_INITIALIZED: strMsg = "MAPI_E_NOT_INITIALIZED"
           Case MAPI_E_NON_STANDARD: strMsg = "MAPI_E_NON_STANDARD"
           Case MAPI_E_NO_RECIPIENTS: strMsg = "MAPI_E_NO_RECIPIENTS"
           Case MAPI_E_SUBMITTED: strMsg = "MAPI_E_SUBMITTED"
           Case MAPI_E_HAS_FOLDERS: strMsg = "MAPI_E_HAS_FOLDERS"
           Case MAPI_E_HAS_MESSAGES: strMsg = "MAPI_E_HAS_MESSAGES"
           Case MAPI_E_FOLDER_CYCLE: strMsg = "MAPI_E_FOLDER_CYCLE"
           Case MAPI_E_AMBIGUOUS_RECIP: strMsg = "MAPI_E_AMBIGUOUS_RECIP"
           Case MAPI_E_INVALID_PARAMETER: strMsg = "MAPI_E_INVALID_PARAMETER"
           Case MAPI_E_NOT_ENOUGH_MEMORY: strMsg = "MAPI_E_NOT_ENOUGH_MEMORY"
           Case MAPI_E_NO_ACCESS: strMsg = "MAPI_E_NO_ACCESS"
           Case Else
                strMsg = "Unknown Error"
       End Select
       If strMsg <> "" Then
          MsgBox "TextReport_SendMail Failed with the error " & strMsg & " (" & lngSendMail & ")", vbCritical
       End If
    End If
    TextReport_SendMail = lngSendMail
   End Function

'*************************************************************
   ' FUNCTION NAME: CountTokens
   '
   ' PURPOSE:
   '   Given a string of delimited items and the delimiter, the number
   '   of tokens in the string will be returned. This function is useful
   '   for dimensioning an array to store the delimited items prior to
   '   calling ParseTokens.
   '
   ' INPUT PARAMETERS:
   '   sSource: A delimited list of tokens
   '   sDelim:  The delimiter used to delimit sSource
   '
   ' RETURN
   '   The number of tokens in sSource, which is the number of delimiters
   '   plus 1. If sSource is empty, 0 is returned.

'*************************************************************
Private Function CountTokens(ByVal sSource As String, ByVal sDelim As String)
Dim iDelimPos As Integer
Dim iCount As Integer

   ' Number of tokens = 0 if the source string is empty
   If sSource = "" Then
      CountTokens = 0

   ' Otherwise number of tokens = number of delimiters + 1
   Else
      iDelimPos = InStr(1, sSource, sDelim)
      Do Until iDelimPos = 0
         iCount = iCount + 1
         iDelimPos = InStr(iDelimPos + 1, sSource, sDelim)
      Loop
      CountTokens = iCount + 1
   End If
End Function

'*************************************************************
' FUNCTION NAME: GetToken
'
' PURPOSE:
'   Given a string of delimited items, the first item will be
'   removed from the list and returned.
'
' INPUT PARAMETERS:
'   sSource: A delimited list of tokens
'   sDelim:  The delimiter used to delimit sSource
'
' RETURN
'   sSource will have the first token removed. The function
'   returns the token removed from sSource.

'*************************************************************
Private Function GetToken(sSource As String, ByVal sDelim As String) As String
Dim iDelimPos As Integer

   ' Find the first delimiter
   iDelimPos = InStr(1, sSource, sDelim)

   ' If no delimiter was found, return the existing string and set
   ' .. the source to an empty string.
   If (iDelimPos = 0) Then
      GetToken = Trim$(sSource)
      sSource = ""

   ' Otherwise, return everything to the left of the delimiter and
   ' .. return the source string with it removed.
   Else
      GetToken = Trim$(left$(sSource, iDelimPos - 1))
      sSource = Mid$(sSource, iDelimPos + 1)
   End If
End Function


'*************************************************************
' SUB NAME: ParseTokens
'
' PURPOSE:
'   Extracts information from a delimited list of items and places
'   it in an array.
'
' INPUT PARAMETERS:
'   Array(): A one-dimensional array of strings in which the parsed
'   tokens will be place
'   sTokens: A delimited list of tokens
'   sDelim:  The delimiter used to delimit sTokens
'
' RETURN
'   None
'*************************************************************
Private Sub ParseTokens(MyArray() As String, ByVal sTokens As String, ByVal sDelim As String)
Dim i As Integer
    For i = LBound(MyArray) To UBound(MyArray)
        MyArray(i) = GetToken(sTokens, sDelim)
    Next
End Sub

0
 

Author Comment

by:skyberg
ID: 7251578
Thanks (at last)

Jan
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now