Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

creating an Outlook instance through Access VBA

Discussion in 'Information Technology' started by sockalingans@gmail.com, Jul 28, 2006.

  1. sockalingans@gmail.com

    sockalingans@gmail.com
    Expand Collapse
    Guest

    good day. Within an existing Access DB application, we have built a
    module to allow users to send emails (through Outlook). Manual
    intervention is necessary, in that users have to click 'send', to send
    the email.
    Opening the first session, and closing it is not a problem. I am having
    trouble starting a second-, third- instance of Outlook, though. This is
    very sporadic, and only happening to one of perhaps twenty users of the
    application (residing in a common folder).
    Any ideas?
    We have checked the references, and version # of reference files and
    they are in sync with the PCs where this functionality is working just
    groovy.

    awaiting a speedy reply...

    socka
     
  2. Loading...

    Similar Threads Forum Date
    Sikh News Punjab to take media help for creating awareness on bird flu (Outlook India) Breaking News Aug 10, 2007
    Canada Ottawa weighs creating ambassador for religious freedom Breaking News Oct 4, 2011
    India SGPC Accused of Creating a Row Breaking News Jan 20, 2011
    Pacific International Gathering of Young Sikhs Focuses on Creating Good Citizens Breaking News Jan 8, 2011
    Are We Creating New Devtas? Sikh Sikhi Sikhism Aug 21, 2009

  3. Danny J. Lesandrini

    Danny J. Lesandrini
    Expand Collapse
    Guest

    Maybe I'm confused here, but are you allowed to open multiple sessions of
    Outlook? In my experience, multiple instances (as viewed in Task Manager)
    suggest a failure of some kind, like Outlook failed to close due to Active
    Sync being attached. I know that's not your problem, but my question is,
    Why do you want to open multiple instances of Outlook?

    Once Outlook is open, then additional requests should use the open session.
    Below is some code that demonstrates this, using GetObject() first to see if
    you can attach to an open session, and then CreateObject() if that fails.

    I may be way off here, but if so, then I simply misunderstood the question.
    --
    Danny J. Lesandrini
    dlesandrini@hotmail.com
    http://amazecreations.com/datafast


    <sockalingans@gmail.com> wrote in message news:1147234225.881862.180130@i40g2000cwc.googlegroups.com...
    > good day. Within an existing Access DB application, we have built a
    > module to allow users to send emails (through Outlook). Manual
    > intervention is necessary, in that users have to click 'send', to send
    > the email.
    > Opening the first session, and closing it is not a problem. I am having
    > trouble starting a second-, third- instance of Outlook, though. This is
    > very sporadic, and only happening to one of perhaps twenty users of the
    > application (residing in a common folder).
    > Any ideas?
    > We have checked the references, and version # of reference files and
    > they are in sync with the PCs where this functionality is working just
    > groovy.
    >
    > awaiting a speedy reply...
    >
    > socka
    >




    Option Compare Database
    Option Explicit

    Dim mOutlookApp As Outlook.Application
    Dim mNameSpace As Outlook.NameSpace
    Dim mFolder As MAPIFolder
    Dim mItem As MailItem
    Dim fSuccess As Boolean


    ' First function sets the Outlook Application
    ' and Namespase objects and opens MS Outlook
    Public Function GetOutlook() As Boolean
    On Error Resume Next


    ' Assume success
    fSuccess = True

    Set mOutlookApp = GetObject(, "Outlook.application")


    ' If Outlook is NOT Open, then there will be an error.
    ' In case of error, attempt to open Outlook
    If Err.Number > 0 Then
    Err.clear
    Set mOutlookApp = CreateObject("Outlook.application")

    If Err.Number > 0 Then
    MsgBox "Could not create Outlook object", vbCritical
    fSuccess = False
    Exit Function
    End If
    End If


    ' If we've made it this far, we have an Outlook App Object
    ' Now, set the NameSpace object to MAPI Namespace
    Set mNameSpace = mOutlookApp.GetNamespace("MAPI")

    If Err.Number > 0 Then
    MsgBox "Could not create NameSpace object", vbCritical
    fSuccess = False
    Exit Function
    End If

    GetOutlook = fSuccess

    End Function


    ' Next function reads user entered values and
    ' actually sends the message
    Public Function SendMessage() As Boolean
    On Error Resume Next

    Dim strRecip As String
    Dim strSubject As String
    Dim strMsg As String
    Dim strAttachment As String

    strSubject = Nz(Me!txtSubject,"")
    strRecip = Nz(Me!txtRecipient,"")
    strMsg = Nz(Me!txtBody,"")
    strAttachment = Nz(Me!txtAttachment,"")

    If Len(strRecip) = 0 Then
    strMsg = "You must provide a recipient."
    MsgBox strMsg, vbExclamation, "Error"
    Exit Function
    End If


    ' Assume success
    fSuccess = True

    If GetOutlook Then
    Set mItem = mOutlookApp.CreateItem(olMailItem)
    mItem.Recipients.Add strRecip
    mItem.Subject = strSubject
    mItem.Body = strMsg

    If Len(strAttachment) > 0 Then
    mItem.Attachments.Add strAttachment
    End If

    mItem.Save
    mItem.Send
    End If

    If Err.Number > 0 Then fSuccess = False
    SendMessage = fSuccess

    End Function
     

Share This Page