473,513 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linking Ms acces with an e-amil package

1 New Member
Wondering if its possible to link a table with e-mail addresses in it, with an e-mail package, sending out a standardised e-mail to certain people within the database table.

Many Thanks

ajc
Oct 23 '07 #1
1 1351
Kevin Wilcox
68 New Member
Yes it is, you can send through outlokk. Here's some sample code, you'll need to modify it to suit.

Expand|Select|Wrap|Line Numbers
  1. Public Sub SendOutlookMessage( _
  2.     strEmailAddress As String, _
  3.     strEmailCCAddress As String, _
  4.     strEmailBccAddress As String, _
  5.     strSubject As String, _
  6.     strMessage As String, _
  7.     blnDisplayMessage As Boolean, _
  8.     Optional strAttachmentFullPath As String)
  9.  
  10. '* Copy this code and paste it into a new Access
  11. '* Module. Click Tools > References and make sure
  12. '* that "Microsoft Office Outlook x.0 Object Library"
  13. '* is checked.
  14. '*
  15. '* This subroutine sends an e-mail message through
  16. '* MS Outlook. If the "blnDisplayMessage" parm is
  17. '* set to "False", the message is placed in the
  18. '* Outlook Outbox. "True" displays the message, and
  19. '* user will have to click "Send" to send it.
  20. '*
  21. '* Ex.:
  22. '*
  23. '* SendOutlookMessage _
  24. '*      "john@doe.com", _
  25. '*      "ccJane@doe.com", _
  26. '*      "bccSue@doe.com", _
  27. '*      "Subject", _
  28. '*      "Body of Message", _
  29. '*      False, _
  30. '*      "C:\My Documents\MyAttachmentFile.txt"
  31.  
  32. Dim objApp As Outlook.Application
  33. Dim objOutlookMsg As Outlook.MailItem
  34. Dim objOutlookRecipient As Outlook.Recipient
  35. Dim objOutlookAttach As Outlook.Attachment
  36. Dim blnOutlookInitiallyOpen As Boolean
  37. Dim strProcName As String
  38.  
  39. On Error Resume Next
  40. strProcName = "SendOutlookMessage"
  41.  
  42. blnOutlookInitiallyOpen = True
  43. Set objApp = GetObject(, "Outlook.Application")
  44. If objApp Is Nothing Then
  45.     Set objApp = CreateObject("Outlook.Application")
  46.     '* Outlook wasn't open when this function started.
  47.     blnOutlookInitiallyOpen = False
  48. End If
  49. If Err <> 0 Then Beep: _
  50.     MsgBox "Error in " & strProcName & " (1): " _
  51.         & Err.Number & " - " & Err.Description: _
  52.     Err.Clear: _
  53.     GoTo Exit_Section
  54.  
  55. 'Create the message
  56. Set objOutlookMsg = objApp.CreateItem(olMailItem)
  57. If Err <> 0 Then Beep: _
  58.     MsgBox "Error in " & strProcName & " (2): " _
  59.         & Err.Number & " - " & Err.Description: _
  60.     Err.Clear: _
  61.     GoTo Exit_Section
  62.  
  63. With objOutlookMsg
  64.     Set objOutlookRecipient = .Recipients.Add(strEmailAddress)
  65.     objOutlookRecipient.Type = olTo
  66.     If strEmailCCAddress = "" Then
  67.     Else
  68.         Set objOutlookRecipient = .Recipients.Add(strEmailCCAddress)
  69.         objOutlookRecipient.Type = olCC
  70.     End If
  71.     If strEmailBccAddress = "" Then
  72.     Else
  73.         Set objOutlookRecipient = .Recipients.Add(strEmailBccAddress)
  74.         objOutlookRecipient.Type = olBCC
  75.     End If
  76.     .Subject = strSubject
  77.     .Body = strMessage
  78.  
  79.     '* Add attachments
  80.     If Not IsMissing(strAttachmentFullPath) Then
  81.         If Trim(strAttachmentFullPath) = "" Then
  82.         Else
  83.             Set objOutlookAttach = .Attachments.Add(strAttachmentFullPath)
  84.             If Err <> 0 Then Beep: _
  85.                 MsgBox "Error in " & strProcName & " (3): " _
  86.                     & Err.Number & " - " & Err.Description: _
  87.                 Err.Clear: _
  88.                 GoTo Exit_Section
  89.         End If
  90.     End If
  91.  
  92.     If blnDisplayMessage Then
  93.         .Display
  94.     Else
  95.         '* Send message by putting it in the Outbox
  96.         .Send
  97.     End If
  98. End With
  99.  
  100. If Err <> 0 Then Beep: _
  101.     MsgBox "Error in " & strProcName & " (99): " _
  102.         & Err.Number & " - " & Err.Description: _
  103.     Err.Clear: _
  104.     GoTo Exit_Section
  105.  
  106. Exit_Section:
  107.     On Error Resume Next
  108.     If Not blnOutlookInitiallyOpen Then
  109.        objApp.Quit
  110.     End If
  111.     Set objApp = Nothing
  112.     Set objOutlookMsg = Nothing
  113.     Set objOutlookAttach = Nothing
  114.     Set objOutlookRecipient = Nothing
  115.     On Error GoTo 0
  116. End Sub
Oct 24 '07 #2

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

Similar topics

4
2754
by: Kona | last post by:
Hello, I would like to known if it is possible to limit acces to a UDB database on Solaris system through db2connect to only specified clients ? My client is a db2connect on Windows platform. ...
1
1560
by: TTD_hck | last post by:
Hello, I need suggestions for the following. I have a acces 97 database and with a script command in acces 97, I can e-mail a file via outllok. I do this with the folowing command in Acces 97:...
0
2217
by: gasturbtec | last post by:
please help im new at access programming and i just got this project dropped in my lap because the old programmer quit. i've been doing ok so far but now i need to add code to an existing database...
0
1165
by: John Smith | last post by:
I am currently using excel to manage a small database. The problem is my database is getting big and I need more then the 65000 lines excel can have. I have considered access but it lacks some...
1
1598
by: Admir Hod?ic via AccessMonster.com | last post by:
I use some old fashion program whit DBF files and now i step by step moving thth to acces. Problem occurs when i try to link DBF tables whit MEMO FILED wich requvest file whit ''name''.ftp extension...
5
2437
by: Mrozu | last post by:
Hi I have frm1. On this form button.Click code for this button is: Dim frm2 as New frm2 frm2.show So after click, frm2 form is shown.
3
2033
by: tomPee | last post by:
Hi, I have the following problem: I am trying to make some sort of base class menu that i can then use to derive other menu's from. Those menu's should then be able to interact with each other....
2
1171
by: throwerm72 | last post by:
I currently have and Access DB that has imported/linked tables from a MySQL databse running on a server (using and ODBC connection). I need to link the another Access DB with the same tables to my...
6
1444
by: zaankanter | last post by:
Hi, This my problem. After distribution of my acces-application I want the new user to be able to enter his Name-adress-etc values, in a one-row table called program-variables. These will be used...
3
1898
by: bilalkhan | last post by:
Hello I m using MS Acces 2007, I need to create a form through which a user can enter all the parameter values in the form and these values will automatically picked by a query: Here is the...
0
7160
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...
0
7525
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...
0
5685
agi2029
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,...
1
5086
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...
0
4746
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...
0
3233
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...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
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 ...
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.