473,749 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to open outlook to run behind my application?

2 New Member
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
1 2959
Dean Kemp
2 New Member
Ok, i have it sorted. used a yes no dialog box.
Thanks
Feb 23 '11 #2

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

Similar topics

1
6908
by: deko | last post by:
Does this code look correct? Private Sub cmdCalendar_Click() Dim mOutlookApp As Outlook.Application Dim mNameSpace As Outlook.NameSpace Set mOutlookApp = New Outlook.Application Set mNameSpace = mOutlookApp.GetNameSpace("MAPI") mNameSpace.GetDefaultFolder(olFolderCalendar).Display Set mNameSpace = Nothing Set mOutlookApp = Nothing
4
398
by: PerryC | last post by:
All, How to ensure SendObject open Outlook and Not Outlook Express? Most pc here at work will default to open OL but on one pc, it open up OL Express. How to fix this in the code? P.S.: I thought I posted this yesterday, but somehow I did not see the post myself. Sorry, if I double post.
7
2340
by: Kathy Burke | last post by:
Hi, I need (if possible) to open a desktop application (vb windows app) from a button on an aspx form. How can this be done so that the app opens on desktop not within the browser? TIA for any help. Kathy
14
5188
by: C | last post by:
Hi, From my ASP.NET application when the user clicksa button I want to be able to programmatically open Outlook, create a new mail, add attachments and set the body text. Is this possible? C.
6
25537
by: Sean | last post by:
I am looking for an open source accounting application written in C#. I have looked at maybe doing something with Accounting Express, but I wanted to know some opinions. The reason I am looking for open source is that this package is the same as every other package except some of the rules and deductions are very particular to these clients. The clients are mainly government employees so the package needs to except all the weird...
2
1979
by: vincent90152900 | last post by:
How to I open a Word application inside a frame of Internet Explorer and Firefox? Many thanks for your replying.
2
6199
by: vincent90152900 | last post by:
How to open a word application inside an Internet Explorer and Firefox? This discussion is open for suggestion. Many thanks for replying.
0
906
by: nikhilatkgp | last post by:
Hi, I want to read the file while it is open in another application for writing the application which is writing is not in my control. so application which will read is in my control this will be a real time thing How i can implement this thing. Please help me in this Thanks in advance
23
5973
by: andyoye | last post by:
How can I launch Outlook on users machines when they click a button on a web form (InfoPath)? Thanks
8
4257
by: vatz | last post by:
I am using Java to open a window application. i need to open it in a specified size. Please let me know how to do this...Thanks in advance... - Vatz
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6800
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.