Results 1 to 7 of 7
  1. #1
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486

    Calling access for email leaves it in the background

    I have an application where I write a report and excel file to a folder, then i open an email in outlook and attach those files.



    My problem is that when the email opens it is in the background and the user has to click to bring up the email to send it. I know it is not a big problem but the user does this a lot and it is just annoying to them.

    Is there any way to get the email to open as the top window. It won't do any good to minimize access to see the window because then they will have to click to bring access back up again.

    Thanks

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I cannot recall ever having that experience. Maybe there is something in your code that makes the Outlook message window not be the active pane. Suggest you copy/paste and post the relevant code. Please paste within code tags (use # button on posting toolbar) whenever you post more than a few lines of code.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    To send the email I use the following code to call a function:

    Code:
    Call SendHTMLEmail(strTo, strSubject, strBody, 1, , spath & "" & sName & "" & sFileName, spath & "" & sName & "" & sExcelFileName)
    The function is:

    Code:
    Function SendHTMLEmail(strTo As String, strSubject As String, strBody As String, _
                        bEdit As Boolean, _
                       Optional strBCC As Variant, Optional AttachmentPath As String, Optional AttachmentPath2 As String)
    'Send Email using late binding to avoid reference issues
       Dim objOutlook As Object
       Dim objOutlookMsg As Object
       Dim objOutlookRecip As Outlook.Recipient
       Dim objOutlookAttach As Outlook.Attachment
       Dim i As Integer
       Const olMailItem = 0
     
       On Error GoTo ErrorMsgs
     
       Set objOutlook = CreateObject("Outlook.Application")
     
       Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
       With objOutlookMsg
          Set objOutlookRecip = .Recipients.Add(strTo)
          objOutlookRecip.Type = 1
     
          'If Not IsMissing(strBCC) Then
          '  Set objOutlookRecip = .Recipients.Add(strBCC)
          '  objOutlookRecip.Type = 3
          'End If
          .BCC = "Accounting@trinitychem.com"
          .Subject = strSubject
          .HTMLBody = strBody
          .Importance = 1  'Importance Level  0=Low,1=Normal,2=High
          
          ' Add attachments to the message.
          If Not IsMissing(AttachmentPath) Then
            
                If AttachmentPath <> "" Then
                    Set objOutlookAttach = .Attachments.Add(AttachmentPath)
                    If AttachmentPath2 <> "" Then
                        Set objOutlookAttach = .Attachments.Add(AttachmentPath2)
                    End If
                End If
          End If
     
          If bEdit Then 'Choose btw transparent/silent send and preview send
            .Display
          Else
            .Send
          End If
       End With
     
       Set objOutlookMsg = Nothing
       Set objOutlook = Nothing
       Set objOutlookRecip = Nothing
       Set objOutlookAttach = Nothing
     
    ErrorMsgs:
       If Err.Number = "287" Then
          MsgBox "You clicked No to the Outlook security warning. " & _
          "Rerun the procedure and click Yes to access e-mail " & _
          "addresses to send your message. For more information, " & _
          "see the document at http://www.microsoft.com/office" & _
          "/previous/outlook/downloads/security.asp."
          Exit Function
       ElseIf Err.Number <> 0 Then
          MsgBox Err.Number & " - " & Err.Description
          Exit Function
       End If
    End Function

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I think someone mentioned code tags?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    Indeed they did :-)

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Not sure of the idea of late binding for some objects like Outlook, but then earling binding for Recipient etc? Shouldn't they be objOutlook.Recipient ?, never tried it.
    Perhaps set to early binding and see what that produces?

    I have used much the same method, but with early binding as DB was only for me, and my emails always came to the forefront?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Works fine for me. You are running this from what event?
    A couple of comments:
    strBCC doesn't make much sense to me as a function parameter. The code will simply override it if you pass a value to the function.

    Ismissing(attachmentpath)

    will always return false regardless of whether or not there is a value. IsMissing isn't for strings. The variable should be a variant.
    If there can be an attachmentPath2 but no attachmentPath1 then 2 won't get attached.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 08-25-2018, 04:55 PM
  2. Calling an API from my VBA Access form
    By newbie30 in forum Access
    Replies: 1
    Last Post: 07-24-2018, 10:04 AM
  3. Replies: 12
    Last Post: 10-31-2016, 02:21 PM
  4. How to Calculate Leaves Left
    By Faiza in forum Queries
    Replies: 6
    Last Post: 06-06-2013, 11:02 AM
  5. Calling Excel from Access
    By Terry Lawson in forum Programming
    Replies: 2
    Last Post: 02-06-2011, 05:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums