Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Automated Email Alerts

Continued from the previous post: Configure Outlook for Lotus Notes.

The procedure we are about to explore applies to both Internet and Intranet emails. We have already configured Microsoft Outlook with a Lotus Notes profile for users who wish to send scheduled emails from Microsoft Access within a Local Area Network (LAN).

When the If SendObject Action is invoked with the appropriate parameters, Microsoft Access will utilize the default Outlook profile—whether configured for Internet or Lotus Notes—to retrieve the target email addresses and transmit messages accordingly.

In our scenario, we aim to send mail alerts on a weekly schedule, which requires some preliminary setup. Specifically, we need to create two small tables to support the automation process.

Address Book Table.

  1. We will create a local Address Book table within the Access database to store the email addresses of recipients.

    Note: It is also possible to link the Microsoft Outlook or Lotus Notes Address Book directly to a Microsoft Access database. However, for our purpose, a simplified local table is preferred.

    While your Outlook or Lotus Notes Address Book may contain numerous contacts, our scheduled mail alerts will only be sent to a specific group of individuals relevant to the subject matter. Therefore, we will maintain a curated list of these recipients in a dedicated local table, populated with selected entries from the configured mail profile's Address Book. (Refer to the fifth image in the previous post titled Configure Outlook for Lotus Notes for context.)

    A sample layout of this local Lotus Notes Mail Address Table is shown below:

    We can use VBA code to read the contents of the local address table and construct the To and Cc fields of the email message dynamically.

    Lotus Notes email addresses are often long and structured, typically containing location names, department identifiers, and organizational units, separated by forward slashes. A typical address may look like:

    Nancy Davolio/Ohio/hrd/Orgzn01@Orgzn01

    However, for our local address table in Access, we only need to store the display name — typically the First Name and Last Name (e.g., Nancy Davolio). When the mail is sent via Lotus Notes, the application will resolve the full email address automatically by matching the display name against the entries in its main Address Book and insert the complete address into the email.

    In some cases, the contents of the report attached to the email may be relevant only to specific recipients, and we may wish to exclude others from receiving that particular message. To implement such targeted email distribution, we need a way to filter out unrelated addresses from the Address Book for the current mailing.

    This can be achieved by using a unique identifier, such as an Employee Code, which should be recorded in both the report’s source data and the local Address Book table (refer to the ECODE field in the Address Book example above). With this common field in place, we can link the two datasets and retrieve only those email addresses that match the relevant employee codes from the report.

    Alternatively, the program can search for each employee code from the report’s source data within the address table and extract the corresponding email addresses. This approach ensures that report attachments are sent only to the appropriate recipients, maintaining both relevance and confidentiality.

    However, for now, we will proceed with a simpler method in our demonstration.

    Email Scheduling

  2. The second required table is a Control Parameter Table for the email automation program. This table stores the weekly mail alert schedule and other related control settings necessary for managing the automated email process.

    A sample structure of the Parameter Table is shown in the image below.


Configuring a Machine.

Although the application may be shared across multiple users on different PCs, it is not necessary to configure every machine for sending emails. In fact, we want to avoid having emails sent from multiple sources. To ensure consistency, the program will identify the designated mail-sending machine by checking the active computer name at runtime. This is achieved by storing the authorized Computer Name in a control field and comparing it with the name of the current machine before executing the mail procedure.

  1. To find your computer's name, follow either of the methods below:

    Method 1: Using System Properties

    • Right-click the My Computer (or This PC) icon on your desktop and select Properties from the context menu.

    • In the System Properties window, go to the Computer Name tab.

    • Your computer’s name will be shown next to the Full computer name label.

    Method 2: Using the Command Prompt

    • Click the Start menu and select Run.

    • In the dialog box, type cmd and click OK to open the Command Prompt.

    • At the prompt, type set and press Enter.

    • A list of environment variables will appear. Look for the entry COMPUTERNAME=X, where X is your system’s name.

We can check for this value using the VBA Environ() Function with the parameter value "COMPUTERNAME".

X = Environ("COMPUTERNAME")

Our email alert is scheduled to be sent once a week, on a specific day—let’s say every Monday. We assume the application will be opened daily by users for regular use. Each time the application launches, it will perform a check against the email schedule.

If the current day is Monday, the program will initiate the mail-sending process. However, to avoid duplicate emails, the report should be sent only once per day, regardless of how many times the application is opened on that Monday.

It’s also possible that the user might forget to open the application on Monday, or the scheduled day falls on a holiday, causing the email alert to be missed. In such cases, the program should detect the missed schedule and send the overdue email the next time the application is opened, regardless of the day.

To support this behavior, we will store the last scheduled date in a control parameter table. This allows the application to determine whether the current day has passed the scheduled date and act accordingly. For our example, we will begin with a sample date: Monday, November 19, 2007.

The Email Sending VBA Code

With the above groundwork completed, our preparation phase is now complete. It’s time to move on to the VBA code implementation.

Copy the Main Program provided below and paste it into a standard module in your Access project. After pasting the code, save the module to proceed further.

Public Function SendWeeklyMail()
'--------------------------------------------------------
'Author : a.p.r. pillai
'Date   : 01/11/2007
'--------------------------------------------------------
Dim db As Database, rst As Recordset
Dim m_Addto As String, m_Cc As String, j As Integer
Dim msgBodyText As String, m_Subject As String
Dim m_MailDate, m_ComputerName As String, chk_CName As String

On Error GoTo SendWeeklyMail_Err

'Field Name and Table Name are same
m_MailDate = DLookup("MailDate", "MailDate")
m_ComputerName = DLookup("ComputerName", "MailDate")
chk_CName = Environ("COMPUTERNAME")

'identify the Mail Client Computer
If chk_CName  = m_ComputerName Then
   Exit Function
End If

'Verify Mail Schedule
If m_MailDate + 7 > Date Then
    Exit Function ' mail not due
End If

m_Addto = ""
m_Cc = ""
j = 0

'Create Address List
Set db = CurrentDb
Set rst = db.OpenRecordset("Add_Book", dbOpenDynaset)
Do While Not (rst.EOF)
    If rst!TO Then
        If Len(m_Addto) = 0 Then
            m_Addto = rst![MailID]
        Else
            m_Addto = m_Addto & ", " & rst![MailID]
        End If

    ElseIf rst![cc] Then

        If Len(m_Cc) = 0 Then 
           m_Cc = rst![MailID]
        Else
            m_Cc = m_Cc & ", " & rst![MailID]
        End If

    End If
rst.MoveNext
Loop
rst.Close

m_Subject = "BANK GUARANTEE RENEWAL REMINDER"

msgBodyText = "Bank Guarantee Renewals Due weekly Status Report as on " _& Format(Date, "dddd, mmm dd,yyyy") & " which expires within next 15 days Cases is attached for review and " & "necessary action. "
msgBodyText = msgBodyText & vbCr & vbCr & "Machine generated email, " & " please do not send reply to this email." & vbCr

'replace x with your Lotus Notes password retaining the ~ character at end. 
SendKeys "xxxxxxx~", False

DoCmd.SendObject acReport, "BG_Status", "SnapshotFormat(*.snp)", m_Addto, m_Cc, "", m_Subject, msgBodyText, False, ""

'Update MailDate to current date (if Monday) or date of
'previous Monday, if the mail was send after the due date.

Set rst = db.OpenRecordset("MailDate", dbOpenDynaset)
rst.Edit
Do While rst![MailDate] + 7 <= Date
  rst![MailDate] = rst![MailDate] + 7
Loop
rst.Update
rst.Close

SendWeeklyMail_Exit:
Exit Function

SendWeeklyMail_Err:
MsgBox Err.Description, , "SendWeeklyMail()"
Resume SendWeekly
Mail_Exit

End Function

Important Note:
In the above code, you will need to modify the SendKeys "xxxxxxx~", False line. Replace the x characters with your Lotus Notes password, ensuring the tilde character (~) is retained, as it simulates the Enter keystroke.

This line is intended to automatically pass the Lotus Notes password in anticipation of the login prompt, allowing the process to continue without user intervention. However, since the mail may be routed through multiple layers, this approach is somewhat unreliable—the timing may not always align with the prompt. If this fails, Lotus Notes will still request the password, and you’ll need to enter it manually and press Enter.

For Internet users (i.e., sending via SMTP), this line can be disabled by simply commenting it out with a single quote ('), If Outlook has already been configured to store the email password.

To ensure a smooth process at application startup, we’ll also include a few lines of code in the Control Screen module to introduce a brief delay after the application opens, before calling the SendWeeklyMail() procedure.

' put the next line at the header section of the Module
Dim i as integer 

Private Sub Form_Load()
   i = 0
   Me.TimerInterval = 1000
End Sub

Private Sub Form_Timer()
i=i+1
If i = 16 then ' 15 seconds delay
   Me.Timerinterval = 0
    SendWeeklyMail
End if
End Sub

Copy and paste the above lines in the Control Screen Module, save, and close the Form. Try out the Automated pre-scheduled Email Procedure.

Share:

Configure Outlook for Lotus Notes

Continued from earlier Post: MS-Access and Emails

We have seen that sending emails from Microsoft Access is quite straightforward, just like other familiar methods. With a few clicks, we can send emails with MS Access objects attached. The available output formats for the attachment depend on the type of object selected. For example, if a VBA code module is selected, it will be automatically converted into plain text format before being attached to the email.

As mentioned in an earlier post, we can automatically send mail alerts on important matters within a Local Area Network (LAN) using email transport services like Lotus Notes, directly from a Microsoft Access application.

However, before we delve into the mail-sending procedures and related programs, we must first configure Microsoft Outlook on one of the PCs to work with Lotus Notes and use its contact list for managing recipients.

Access Mail Client

Your application may be shared by multiple users across different PCs; however, all outgoing emails should be routed through a single designated machine—let’s call it the Access Mail Client. This machine must be configured specifically for sending emails via Lotus Notes.

Lotus Notes requires both a Mail Server and a Client application installed on each PC. Accordingly, the Access Mail Client must have the Lotus Notes Client installed and actively used for sending emails. Additionally, this machine will require a unique Lotus Notes ID file and an associated Lotus Notes email account.

NB: If you prefer that Mail Alerts from your Access application do not display a personal user ID as the sender, a dedicated Lotus Notes mail ID should be created for this purpose. The Lotus Notes Client on the Access Mail Client machine must then be configured using this ID. You may need to consult your Lotus Notes Administrator to set up and configure this special account.

Configuring MS Outlook with Lotus Notes.

We will now explore the Microsoft Outlook configuration steps, accompanied by a few illustrative images and explanations of what each step accomplishes.

  1. Your Lotus Notes ID file must be registered within Lotus Notes itself to make it accessible to external programs, such as Microsoft Outlook. To do this, open Lotus Notes and log in with your User ID and password. From the File menu, select MobileEdit Current Location. The Location: Office (Network) settings screen will appear.

  2. Click on the Advanced Tab and select Basics from the displayed 2nd set of Tabs. See the Image below.

  3. Click on the text box next to the User ID label to activate it, then click on the Search (magnifying glass) icon located below the label to browse for your Lotus Notes User ID file. The typical file path is:

    makefile
    X:\Lotus\Notes\Data\filename.id

    Here, X represents the drive where Lotus Notes is installed, and the filename usually resembles your name or the one assigned by your Lotus Notes administrator. Locate this .id file and insert it into the text box.

    This file contains your Lotus Notes email ID and password, which Microsoft Outlook requires to access the Lotus Notes Contact List and to send or receive emails through Lotus Notes.

  4. Close the Control after inserting the Location reference and minimize Lotus Notes.

  5. Open the Control Panel from the Start Menu → Settings, then double-click the Mail icon to display the Mail Setup control, which includes the Services, Delivery, and Addressing tabs (as shown in the image below).

    Please note that if your version of Microsoft Outlook is not installed as Corporate or Workgroup, the available options and layout may appear differently. The screenshots referenced are based on a Microsoft Office 2000 installation.

  6. Click on the Services tab. If no mail services have been previously configured, the Profiles window will appear empty.

  7. Next, go to the Delivery tab and select Lotus Notes Message Store in the control below. At this point, you may be prompted to enter your Lotus Notes password to complete the setup. Once this step is finished, the Information Service entry for Lotus Notes Transport will appear in the following window.

  8. Click the Add button to open the Add Services to Profile list. From the available options, select Lotus Notes Mail and click to add it to the Profiles window.

  9. Click on the Addressing tab in the Mail Setup control panel. You can choose either the Lotus Notes Main Address Book or your personal Lotus Notes Address Book—which may include selected entries copied from the main address book—and assign it to the appropriate controls. Refer to the image below for guidance.

  10. Click Apply to save the updated settings, and then click OK to close the window. These configuration steps can also be accessed through the Options menu under Tools in Microsoft Outlook.

  11. Next, we need to define how contact names are stored in the Address Book, which can be done from within Outlook.

  12. Open Microsoft Outlook and select Preferences from the Tools menu.

  13. Click on the Contact Options button.

  14. Choose the appropriate settings in both controls as shown in the image below, then click OK to confirm.

  15. The first control settings say that while sending mails, insert the Names in this order, but while storing the values in the Address Book, use the format in the second control.

    When you look for the Email addresses manually in the Address Book, it will be displayed in the second format, and you can search for the names by typing the first few characters of the first name in the lookup control.

    But when we attempt to send mail from MS-Access, we must present the email ID to Lotus Notes in the first format.

    The Image of the Lotus Notes Mail ID lookup control is given below for reference. I have edited the image to insert those names more familiar to you. Check the name displayed in the left window and how the name format changes when it is inserted in the To line.

  16. You may now try to send an e-mail through Lotus Notes Mail manually from MS-Access, as we did in an earlier session, using some of your friends' Lotus Notes IDs. During the mail transmitting point, Lotus Notes will prompt for the password.

Next, we will see how to send the Mail Alerts automatically from Microsoft Access through Lotus Notes at scheduled intervals.

Share:

MS-Access and E-Mail

Introduction

You are unlikely to use Microsoft Access to send personal emails over the Internet, especially when so many other convenient options are available.

However, if your Access application regularly generates reports that need to be shared with remote users—and you are currently sending them via traditional postal services—email becomes a practical and efficient alternative worth considering.

If you are connected to a Local Area Network (LAN), reports can also be distributed internally through intranet mail services such as Lotus Notes.

For both Internet and Intranet mail to function properly, Microsoft Outlook must be configured as the communication bridge between Microsoft Access and the mail transport system—whether it’s the SMTP server of your Internet Service Provider (ISP) or an Intranet mail system like Lotus Notes. If you’re already using Microsoft Outlook to send and receive emails, then it's likely already set up correctly. Outlook also maintains a Contact List, which can be used to select prospective email recipients.

Note: Configuring Microsoft Outlook is beyond the scope of this article. For guidance, refer to Outlook’s built-in Help or the documentation provided by your ISP. That said, we will cover the configuration steps for using Outlook with Lotus Notes intranet mail in upcoming posts.

Outlook Versions.

There are two types of Microsoft Outlook installations:

  1. Internet Mail Only – typically used for personal email through services like Gmail or Outlook.com.

  2. Corporate or Workgroup – configured for use in business environments, often connected to Microsoft Exchange or intranet mail systems like Lotus Notes.

To check which version is installed on your PC:

  • Open Microsoft Outlook.

  • Click on the Help menu (in older versions) and select About Microsoft Outlook.

If it is the Corporate or Workgroup version, you will see this label explicitly displayed in the upper section of the About screen.

Scenario 1: Automated Birthday Greetings

If your company is a service-oriented organization—such as a Bank, Insurance Firm, or Health Clinic—you likely maintain customer profiles that include date of birth. You can configure your Microsoft Access application to automatically:

  • Identify customers whose birthdays fall on the current day.

  • Generate personalized birthday messages using a predefined email template.

  • Send the greeting via Outlook with a single click or fully automated routine.

This adds a personal touch to your service and strengthens customer relationships.

OR

Scenario 2: Notification of Revised Interest Rates

When your bank revises interest rates for Fixed Deposits or Savings Schemes, you may want to:

  • Notify all relevant account holders or only those with deposits maturing soon.

  • Include personalized details such as account number, maturity amount, or new applicable rates.

  • Attach an official circular or brochure in PDF format.

Using Microsoft Access, you can filter target recipients, generate individual messages, and dispatch them through Outlook in a batch process.

OR

Scenario 3: Bank Guarantee Renewal Alerts

If your company extends credit to customers based on renewable Bank Guarantees, your Microsoft Access application can be configured to:

  • Monitor expiry dates of submitted guarantees.

  • Automatically generate email alerts to internal stakeholders or account managers responsible for follow-up.

  • Ensure that reminders are sent well in advance of the renewal due dates, giving ample time to coordinate with the customer.

This proactive approach minimizes credit risk and helps maintain compliance with company policies and financial safeguards.

In all the above scenarios—or in similar situations—the Mail Alert process can be fully automated using VBA programs within Microsoft Access. Toward the end of this series, we will explore a sample procedure for sending emails automatically through Lotus Notes, demonstrating how such integration can streamline communication and improve operational efficiency.

Using Lotus Notes for email.

In the meantime, let us look into a simple mail-sending example that sends a Report as an attachment, in Microsoft Access Snapshot Format, manually.

  1. Open your database and select a Report (avoid choosing the dynamic report we created in the previous session).

  2. Go to the File menu, point to Send To, and click Mail Recipient (as Attachment).

  3. From the list of available file formats, select Snapshot Format.

  4. A dialog box will appear, prompting you to choose a Mail Transport Profile already configured in Microsoft Outlook or to create a new one.

  5. Choose the default profile you typically use to send emails. If you set this profile as the default, this dialog will not appear the next time.

  6. After clicking OK, the email editor screen will open, allowing you to modify the message content before sending.

    See the image below.

  7. Click the To button to select email addresses from the Contacts List in Microsoft Outlook. The Cc button functions the same way.

  8. You will notice that the selected Report has already been converted into Microsoft Access Snapshot Format and attached to the email. If you prefer to send an external file—such as a Word or Excel document—instead, click the Attach... button and browse to select the file from your hard disk.

  9. The blue-colored panel on the right side will remain hidden until you click the Attachment Options button located next to it.

    Two attachment options are available. The default option, Regular Attachment, sends individual copies of the attachment to each recipient. The second option is intended for Intranet mail systems, where the attachment is saved in a shared location accessible to all recipients. This option can be safely ignored in most cases.

  10. You can compose your email in plain text and click the Send button on the toolbar. Microsoft Outlook will handle the rest.

Sample Mail Image

A sample image of the Sent Items display of Microsoft Outlook 2003 is given below for reference.

If you are sending a standard report as an attachment with predefined wording in the email body, the entire process can be automated using a macro. Refer to the configuration of the SendObject Command in the macro design image below for proper setup. 

The SendObject Command

The SendObject command is selected in the Action column of the macro design grid, and the corresponding email-related field values are specified in the property sheet below. If you do not intend to send an Access object as an attachment, the first three property values can be left blank. Setting the Edit Message property to Yes will open the email client, allowing you to edit the message before sending, as demonstrated earlier. If it is set to No, the message will be sent directly through Microsoft Outlook without being displayed on the screen.

You can attach this macro to a Command Button or run it from VBA code using DoCmd.RunMacro "MacroName". If you wish to control the frequency of emails with the report attachment, you should implement a procedure that verifies the scheduled date or day before executing the macro. We will explore such a program—designed to send emails automatically on a weekly schedule—at the end of this series.

Next, we will explore the procedure for configuring Lotus Notes as a mail transport mechanism for sending emails within a Local Area Network (LAN).

Share:

PRESENTATION: ACCESS USER GROUPS (EUROPE)

Translate

PageRank

Post Feed


Search

Popular Posts

Blog Archive

Powered by Blogger.

Labels

Forms Functions How Tos MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Class Module External Links Queries Array msaccess reports Accesstips WithEvents msaccess tips Downloads Objects Menus and Toolbars Collection Object MsaccessLinks Process Controls Art Work Property msaccess How Tos Combo Boxes Dictionary Object ListView Control Query VBA msaccessQuery Calculation Event Graph Charts ImageList Control List Boxes TreeView Control Command Buttons Controls Data Emails and Alerts Form Custom Functions Custom Wizards DOS Commands Data Type Key Object Reference ms-access functions msaccess functions msaccess graphs msaccess reporttricks Command Button Report msaccess menus msaccessprocess security advanced Access Security Add Auto-Number Field Type Form Instances ImageList Item Macros Menus Nodes RaiseEvent Recordset Top Values Variables Wrapper Classes msaccess email progressmeter Access2007 Copy Excel Export Expression Fields Join Methods Microsoft Numbering System Records Security Split SubForm Table Tables Time Difference Utility WScript Workgroup database function msaccess wizards tutorial Access Emails and Alerts Access Fields Access How Tos Access Mail Merge Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Common Controls Conditional Formatting Data Filtering Database Records Defining Pages Desktop Shortcuts Diagram Disk Dynamic Lookup Error Handler External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Message Box Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar updating upload vba code