Hi everybody,
I'm sure that everyone cringes when they see "email" in the subject for posts in the forum, but I'm hoping that what I'm trying to do is different enough to present a challenge instead of an aneurysm. =)
I'm creating a form with a list box of values that, when selected, will create a filter for a report. On this same form, I want to add a command button that will allow the user to send an email with the report, based on the filter criteria, as an attachment. To make things a little bit more interesting, I would like to display the Outlook address book to the user to select the email addresses to send the report (I can't rely on the users to accurately enter email addresses and I don't want to import the contacts because my database is already projected to be extremely large).
I did some homework and found a way to display the Outlook address book using CDO, but once it's displayed I don't know how to capture the email addresses from the alias and then create the email, not to mention have the email automatically send without requiring the user to click 'Send' in Outlook.
Here's the code I "borrowed" from another site: -
Private Sub Command43_Click()
-
-
On Error GoTo err_Session_AddressBook
-
-
Dim objOL As Outlook.Application
-
Dim oOutlook As Object
-
Dim oMail As Object
-
Dim objSession As MAPI.Session
-
Dim colCDORecips As Object
-
Dim strEmail As String
-
-
On Error Resume Next
-
-
Set objOL = GetObject(, "Outlook.Application")
-
-
If Err.Number <> 0 Then
-
Set oOutlook = CreateObject("Outlook.Application")
-
Set oMail = oOutlook.CreateItem(olMailItem)
-
oMail.Display
-
End If
-
-
Set objSession = New MAPI.Session
-
objSession.Logon "", "", False, False
-
-
Set colCDORecips = objSession.AddressBook(, "Pick Names", , , 2, "To: ", "Cc: ")
-
-
objSession.Logoff
-
-
Set colCDORecips = Nothing
-
Set objSession = Nothing
-
Set objOL = Nothing
-
Set oOutlook = Nothing
-
Set oMail = Nothing
-
-
err_Session_AddressBook:
-
If (Err = 91) Then ' MAPI dlg-related function that sets an object
-
MsgBox "No recipients selected"
-
Else
-
'MsgBox "Unrecoverable Error:" & Err
-
End If
-
End Sub
-
Just for the record, I'm completely content using whatever method (including CDO) so long as the email will be sent automatically without the user having to click 'Send', the email will be sent to the users captured from the Outlook address book automation, and the report can be automatically attached without having to save the report to a network folder first.
Thanks,
beacon
Nevermind, I was able to resolve this issue.
For those that are interested, here's the code I used (I wasn't able to resolve the Outlook security, but you can't win them all): -
Private Sub Command43_Click()
-
-
Dim objOL As Outlook.Application
-
Dim oOutlook As Object
-
Dim oMail As Object
-
Dim objSession As MAPI.Session
-
Dim colCDORecips As Object
-
-
On Error Resume Next
-
-
Set objOL = GetObject(, "Outlook.Application")
-
-
If Err.Number <> 0 Then
-
Set oOutlook = CreateObject("Outlook.Application")
-
Set oMail = oOutlook.CreateItem(olMailItem)
-
End If
-
-
Set objSession = New MAPI.Session
-
objSession.Logon "", "", False, False
-
-
Set colCDORecips = objSession.AddressBook(, "Pick Names", , True, 2, "To: ", "CC: ")
-
-
If colCDORecips Is Nothing Then
-
Exit Sub
-
End If
-
-
For Each col In colCDORecips
-
tmp = tmp & col & ";"
-
Next col
-
-
strFileName = "C:\Temp\Contacts.snp"
-
-
DoCmd.OutputTo acOutputReport, "Contacts", acFormatSNP, strFileName
-
-
With oMail
-
.To = tmp
-
.Subject = "These two files"
-
.BodyFormat = olFormatHTML
-
.HTMLBody = "Please resolve the deficiencies in the attached report."
-
.Attachments.Add strFileName
-
.Send
-
End With
-
-
objSession.Logoff
-
-
'Cleanup
-
'---------------------------
-
Set colCDORecips = Nothing
-
Set objSession = Nothing
-
Set objOL = Nothing
-
Set oOutlook = Nothing
-
Set oMail = Nothing
-
-
'Delete the file created by the SendObject method
-
'---------------------------------------------------
-
Set newFile = CreateObject("Scripting.FileSystemObject")
-
Set newFolder = newFile.GetFile(strFileName)
-
newFolder.Delete
-
-
Exit Sub
-
-
err_Session_AddressBook:
-
If (Err = 91) Then ' MAPI dlg-related function that sets an object
-
MsgBox "No recipients selected"
-
Else
-
MsgBox "Unrecoverable Error:" & Err
-
End If
-
End Sub
-
1 3150
Nevermind, I was able to resolve this issue.
For those that are interested, here's the code I used (I wasn't able to resolve the Outlook security, but you can't win them all): -
Private Sub Command43_Click()
-
-
Dim objOL As Outlook.Application
-
Dim oOutlook As Object
-
Dim oMail As Object
-
Dim objSession As MAPI.Session
-
Dim colCDORecips As Object
-
-
On Error Resume Next
-
-
Set objOL = GetObject(, "Outlook.Application")
-
-
If Err.Number <> 0 Then
-
Set oOutlook = CreateObject("Outlook.Application")
-
Set oMail = oOutlook.CreateItem(olMailItem)
-
End If
-
-
Set objSession = New MAPI.Session
-
objSession.Logon "", "", False, False
-
-
Set colCDORecips = objSession.AddressBook(, "Pick Names", , True, 2, "To: ", "CC: ")
-
-
If colCDORecips Is Nothing Then
-
Exit Sub
-
End If
-
-
For Each col In colCDORecips
-
tmp = tmp & col & ";"
-
Next col
-
-
strFileName = "C:\Temp\Contacts.snp"
-
-
DoCmd.OutputTo acOutputReport, "Contacts", acFormatSNP, strFileName
-
-
With oMail
-
.To = tmp
-
.Subject = "These two files"
-
.BodyFormat = olFormatHTML
-
.HTMLBody = "Please resolve the deficiencies in the attached report."
-
.Attachments.Add strFileName
-
.Send
-
End With
-
-
objSession.Logoff
-
-
'Cleanup
-
'---------------------------
-
Set colCDORecips = Nothing
-
Set objSession = Nothing
-
Set objOL = Nothing
-
Set oOutlook = Nothing
-
Set oMail = Nothing
-
-
'Delete the file created by the SendObject method
-
'---------------------------------------------------
-
Set newFile = CreateObject("Scripting.FileSystemObject")
-
Set newFolder = newFile.GetFile(strFileName)
-
newFolder.Delete
-
-
Exit Sub
-
-
err_Session_AddressBook:
-
If (Err = 91) Then ' MAPI dlg-related function that sets an object
-
MsgBox "No recipients selected"
-
Else
-
MsgBox "Unrecoverable Error:" & Err
-
End If
-
End Sub
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Phil Stanton |
last post by:
Can anyone give me sone code to add addresses from a query to an Outlook
Address book. The problem is that I want to add the new email addresses to a
distribution list, not to the main email list
...
|
by: sfriedman |
last post by:
I've heard that there was a linking utility that would permit me to
link a table or query to my outlook address book. Can anyone tell me
where to find this linking utility and how it works? The...
|
by: Adhiraj |
last post by:
Hi,
Does anyone hav any idea on how to access Microsoft Outlook Address Book
thru' C#?
Thanks in advance,
Adhiraj.
|
by: Adhiraj |
last post by:
Hi,
Has anyone idea on how to access Microsoft Outlook Address Book thru' C# code?
Thanks in advance,
Adhiraj.
|
by: Bob Avallone |
last post by:
MetaPro Systems Inc. Visual Studio Dot Net Tips & Tricks #3 – Direct
Access to
Your Outlook Address Book.
Project Type: VS.NET Windows Application
Code Behind: Visual Basic
I have a project...
|
by: Allophylus |
last post by:
Hi,
I am developing a simple utility that will queries Active Directory and generate a folder in the users MS Outlook 2000 with the respective users' contacts and distribution list.
Everything...
|
by: mattkorguk |
last post by:
Good morning All,
I have built a small database usage utility which basically shows who logged into the Db, when and what version was used.
I'm bringing back the users log on Id such as...
|
by: Alexander Szigetvary |
last post by:
Hi NG!
Is there a way to open the Outlook address book dialog (as in Outlook) using
C#? I am using Outlook 2003 (MS Outlook 11.0 Object Library).
In Outlook 2007 it can be done with...
|
by: Lpitt56 |
last post by:
I am running MS Access 2007 and I want to update an Outlook Address book from my Access Database. I started out by importing the Outlook Address Book as a linked table and it linked fine. I then...
|
by: Mike Miller |
last post by:
Hi,
Am wanting to send email with php and need to access the global
outlook address book. Are there any examples/tutorials on how to do
this?
M
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
|
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 ...
| |