By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,742 Members | 2,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,742 IT Pros & Developers. It's quick & easy.

How to open outlook to run behind my application?

P: 2
Hi
I have designed a button that sends a mail “automated” by the system. But it doesn’t work if outlook is closed. And I have a string of code that opens outlook but then it opens on top of my app.
Is there a way to open outlook to run behind the app.
this is the coding so far.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command131_Click()
  2.  
  3. MyAppID = Shell("C:\Program Files\Microsoft Office\OFFICE12\Outlook.exe", 1)
  4.  
  5.  
  6.   On Error Resume Next
  7.   With GetObject(, "Outlook.Application")
  8.     .ActiveWindow.WindowState = 1   ' olMinimized = 1
  9.   End With
  10.  
  11.  
  12.  
  13. Dim A3 As String
  14. A3 = Me.Contact_Name
  15.  
  16. If IsNull(A3) = True Then
  17. MsgBox "You dont have all the contact details saved on the page!", vbInformation, "Notification"
  18. End If
  19.  
  20. Dim A4 As String
  21. A4 = Forms!Intro!Text288
  22.  
  23. Dim A5 As String
  24. A5 = Me.Trade_Name
  25.  
  26. Dim A6 As String
  27. A6 = Forms!Intro!Text80
  28.  
  29. Dim EMailAdd As String
  30.  
  31.                       If IsNull(EMailAdd = Me.Contact_Email_Address) = True Then
  32.                         MsgBox "You dont have all the contact details saved on the page!", vbInformation, "Notification"
  33.                         Else
  34.                         EMailAdd = Me.Contact_Email_Address
  35.  
  36.                         Dim FilePath As String
  37.                         'FilePath = [Forms]![E-Mail Correspondance]![FileTrigger]
  38.  
  39.  
  40.                         Dim objApp As outlook.Application
  41.                         Dim objOutlookMsg As outlook.MailItem
  42.                         Dim objOutlookRecipient As outlook.Recipient
  43.                         Dim objOutlookAttach As outlook.Attachment
  44.                         Dim blnOutlookInitiallyOpen As Boolean
  45.                         Dim strProcName As String
  46.  
  47.                         On Error Resume Next
  48.                         strProcName = "SendOutlookMessage"
  49.  
  50.                         blnOutlookInitiallyOpen = True
  51.                         Set objApp = GetObject(, "Outlook.Application")
  52.                         If objApp Is Nothing Then
  53.                             Set objApp = CreateObject("Outlook.Application")
  54.                             '* Outlook wasn't open when this function started.
  55.                             blnOutlookInitiallyOpen = True
  56.                         End If
  57.                            If Err <> 0 Then Beep: _
  58.                             MsgBox "Error in " & strProcName & " (1): " _
  59.                                 & Err.Number & " - " & Err.Description: _
  60.                             Err.Clear: _
  61.                             GoTo Exit_Section
  62.  
  63.                         'Create the message
  64.                         Set objOutlookMsg = objApp.CreateItem(olMailItem)
  65.                         If Err <> 0 Then Beep: _
  66.                             MsgBox "Error in " & strProcName & " (2): " _
  67.                                 & Err.Number & " - " & Err.Description: _
  68.                             Err.Clear: _
  69.                             GoTo Exit_Section
  70.  
  71.                         With objOutlookMsg
  72.                             Set objOutlookRecipient = .Recipients.Add(EMailAdd)
  73.                             objOutlookRecipient.Type = olTo
  74.                             If strEmailCCAddress = "" Then
  75.                             Else
  76.                                 Set objOutlookRecipient = .Recipients.Add(strEmailCCAddress)
  77.                                 objOutlookRecipient.Type = olCC
  78.                             End If
  79.                             If strEmailBccAddress = "" Then
  80.                             Else
  81.                                 Set objOutlookRecipient = .Recipients.Add(strEmailBccAddress)
  82.                                 objOutlookRecipient.Type = olBCC
  83.                             End If
  84.                             .Subject = "Individual Batch SOR."
  85.                             .Body = "Good day " + A3 + ". This is an automated e-mail. Please do not reply to this email ."
  86.  
  87.                                     '* Add attachments
  88.                             If Not IsMissing(A2) Then
  89.                                 If Trim(A2) = "" Then
  90.                                 Else
  91.                                   Set objOutlookAttach = .Attachments.Add(A2)
  92.                                   '  Set objOutlookAttach = .Attachments.Add("C:\MIS\Download/Prov-02.xls")
  93.                                   '  Set objOutlookAttach = .Attachments.Add("C:\MIS\Download/Prov-03.xls")
  94.                                   '  Set objOutlookAttach = .Attachments.Add("C:\MIS\Download/Prov-04.xls")
  95.                                   '  Set objOutlookAttach = .Attachments.Add("C:\MIS\Download/Prov-05.xls")
  96.                                   '  Set objOutlookAttach = .Attachments.Add("C:\MIS\Download/Prov-06.xls")
  97.                                   '  Set objOutlookAttach = .Attachments.Add("C:\MIS\Download/Prov-07.xls")
  98.                                   '  Set objOutlookAttach = .Attachments.Add("C:\MIS\Download/Prov-08.xls")
  99.  
  100.                                     'Set objOutlookAttach = A1
  101.                                     If Err <> 0 Then Beep: _
  102.                                         MsgBox "Error in " & strProcName & " (3): " _
  103.                                             & Err.Number & " - " & Err.Description: _
  104.                                         Err.Clear: _
  105.                                         GoTo Exit_Section
  106.                                 'End If
  107.                             'End If
  108.  
  109.                             If blnDisplayMessage Then
  110.                                 .Display
  111.                             Else
  112.                                 '* Send message by putting it in the Outbox
  113.                                 .Send
  114.                             End If
  115.                         'End With
  116.  
  117.                         If Err <> 0 Then Beep: _
  118.                             MsgBox "Error in " & strProcName & " (99): " _
  119.                                 & Err.Number & " - " & Err.Description: _
  120.                             Err.Clear: _
  121.                             GoTo Exit_Section
  122.  
  123. Exit_Section:
  124.                             On Error Resume Next
  125.                             If Not blnOutlookInitiallyOpen Then
  126.                                objApp.Quit
  127.                             End If
  128.                             Set objApp = Nothing
  129.                             Set objOutlookMsg = Nothing
  130.                             Set objOutlookAttach = Nothing
  131.                             Set objOutlookRecipient = Nothing
  132.                             On Error GoTo 0
  133.  
  134. MsgBox "If no error was recieved your request has been sent.", vbInformation, "Notification!"
  135.  
  136.  
  137.  
  138. End If
  139. End If
  140. End With
  141. End If
  142. End Sub
  143.  
Feb 23 '11 #1
Share this Question
Share on Google+
1 Reply


P: 2
Ok, i have it sorted. used a yes no dialog box.
Thanks
Feb 23 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.