Regarding a question that utilizes VBA

AmySciv

Registered User.
Local time
Today, 17:14
Joined
Oct 6, 2003
Messages
10
All-

I am wondering if there is a database that has a possible format so that one could list emails into Outlook. My boss asked me yesterday if there was a way to quickly make a database and from that database send them to Outlook. I figured that I would just email to find out if I could or if it has ever been done before.

Amy
 
Have a look at SendOject in the help files and on this forum. That will get you started.
 
AmySciv said:
I am wondering if there is a database that has a possible format so that one could list emails into Outlook. My boss asked me yesterday if there was a way to quickly make a database and from that database send them to Outlook. I figured that I would just email to find out if I could or if it has ever been done before.

I'm not sue quite what you mean by "list emails into Outlook" and "make a database and from that database send them to Outlook". Are you wanting to look at the emails you already have in Outlook, or are you simply wanting to send emails from Access? If its the latter, this is relatively easy (with some VBA; if you are not familiar with VBA is might take you some time). If its the former, then again this is possible, but not as straightforward. Are you sending any content from the database, such as a report or a table of data? Or just the content of the email itself (i.e. a subject and a body)?
 
Amy,

You can use practically any of the Office suite including outlook directly from Access code (VBA and macros). Nearly (if not all) of the functionality is available. I for instance send up to 1000 individual winzipped password-protected reports directly from an Access Database to multiple end-users using Outlook... it is all completely automated. Further I have some code that looks through my Outlook inbox and saves certain file attachments to specific directories based on certain criteria. Both lots of code take a little understanding, but most things are possible.

If you can answer the questions posed by Reclusive Monkey you may get more detailed answers to your questions. I would be happy to provide some sample code to get you started if I knew what you required.

J.
 
reclusivemonkey said:
I'm not sue quite what you mean by "list emails into Outlook" and "make a database and from that database send them to Outlook". Are you wanting to look at the emails you already have in Outlook, or are you simply wanting to send emails from Access? If its the latter, this is relatively easy (with some VBA; if you are not familiar with VBA is might take you some time). If its the former, then again this is possible, but not as straightforward. Are you sending any content from the database, such as a report or a table of data? Or just the content of the email itself (i.e. a subject and a body)?

Reclusive Monkey:

Basically, I was trying to make the database as easy to use because my boss really is not that gifted in computer applications.

What the boss wants: easy way to develop a program for mass mailouts. He wanted to develop a database that will allow him to keep up with all his clients and contact information.

What I thought he could do was to develop a database that he could pick out the clients that he wanted to send the mass mailouts and the names would go to Outlook just by clicking the names. It might not work because finding a form that will allow this might be difficult. If you have any suggestions, I would greatly appreciate it.

Amy
 
Amy,

Can I suggest something like the following:

Using the customer details that you have stored in a table (?!) create a form with four controls.

The first 2 fields will come from your customer table
Customer Name
Customer Email

The next 2 will just be text boxes
Subject
Email Message

You would create a command button which calls the following code (an on click event):

Code:
Private Sub SendEmail()

PROC_DECLARATIONS:
    Dim olApp As Outlook.Application
    Dim olnamespace As Outlook.NameSpace
    Dim olMail As Outlook.MailItem
    Dim strSQL As String
    Dim strSender As String
    Dim strRecipient As String
    Dim strEmail As String
    Dim strDeliveryDate As Date
    Dim strSubject As String
    Dim strMessage As String
     
PROC_START:
   On Error GoTo PROC_ERROR
   
PROC_MAIN:
   
    'Put on hourglass
    DoCmd.Hourglass True

    'Set parameters for email: recipient name, recipient email, Subject, and Message
    strRecipient = Forms!Formname!txtRecipient
    strEmail = Forms!Formname!txtEmail
    strSubject = Forms!Formname!txtSubject
    strMessage = Forms!Formname!txtMessage
            
    'Create a new instance of an Outlook Application object
    Set olApp = New Outlook.Application
    Set olnamespace = olApp.GetNamespace("MAPI")
    Set olMail = olApp.CreateItem(olMailItem)
                
        With olMail
                
            'Email Details
            .To = strEmail
            '.BCC = populate this if you want someone else copied in to the email
            .Subject = strSubject
            .Body = vbCrLf & "Dear " & strRecipient & "," & vbCrLf & vbCrLf & strSubject
            .Importance = olImportanceNormal ' You can change the importance of the email here
            .ReadReceiptRequested = True 'Sends a confirmation when recipient reads email
            .DeleteAfterSubmit = True 'Deletes from sent Items once email is sent
            '.SentOnBehalfOfName = use this if you want to send from a communal outlook account
            '.Attachments.Add Specify a filename here if you want to add attachments
            .Display 'This will let you display the email
            '.Send When you are happy with your code remove the comment and this line will enable the email to be sent automatically
                
            'Here you could keep a record of every email sent in an audit table
            strDeliveryDate = Format(Now(), "dd/mm/yyyy hh:mm:ss")
            strSQL = "Insert into tblEmailHistory values ('" & strEmail & "', '" & strDeliveryDate & "', '" & strRecipient & "','" & strMessage & "', ' ');"
            MsgBox strSQL
            DoCmd.RunSQL (strSQL)
            
        End With
        
PROC_EXIT:
    On Error Resume Next
    DoCmd.Hourglass False
    Set olApp = Nothing
    Set olnamespace = Nothing
    Set olMail = Nothing
 
PROC_ERROR:
    If Err = -2147467259 Then
        MsgBox "You have exceeded the storage limit on your mail box. Please delete some items before clicking OK", vbOKOnly
        Resume
    End If
    
    If Err = 2501 Then
        MsgBox "You have attempted to cancel the output of the emails." & vbCrLf & _
            "This will cause major problems." & vbCrLf & _
            "Please be Patient"
        Resume
    End If
    MsgBox Err.Number & " " & Err.Description
    Resume PROC_EXIT
   
End Sub

When you become more familiar with the code you can get it to do a lot more.

Hope that this helps.

J.
 
AmySciv said:
Basically, I was trying to make the database as easy to use because my boss really is not that gifted in computer applications.

What the boss wants: easy way to develop a program for mass mailouts. He wanted to develop a database that will allow him to keep up with all his clients and contact information.

The first thing I would suggest is using the addressbook in Outlook. How applicable this is to your situation depends on the number of differing mass mailouts you require. I would think that you should already have most of your contacts already in here. Then its simply a case of adding a "mailout" then adding the relevant contacts to this list. Now if the mass mailout is going to be different every time, then this might not be the best solution. However, doing it this way, if possible, negates the need for a database at all. Let me know what you think of that; if its not viable, you can indeed develop a contacts database (the built in access wizard can help you do this), then you can use one of the many suggested code snippets on the forum.

I am not too familiar with Outlook as I use GroupWise at work, but I seem to remember its pretty simple. I am assuming you are part of a small company and don't have any great tech resources, in which case I would definitely say the KISS (Keep It Simple, Stupid) principal is worth remembering!
 
Jibbadiah said:
Amy,

Can I suggest something like the following:

Using the customer details that you have stored in a table (?!) create a form with four controls.

The first 2 fields will come from your customer table
Customer Name
Customer Email

The next 2 will just be text boxes
Subject
Email Message

You would create a command button which calls the following code (an on click event):

Code:
Private Sub SendEmail()

PROC_DECLARATIONS:
    Dim olApp As Outlook.Application
    Dim olnamespace As Outlook.NameSpace
    Dim olMail As Outlook.MailItem
    Dim strSQL As String
    Dim strSender As String
    Dim strRecipient As String
    Dim strEmail As String
    Dim strDeliveryDate As Date
    Dim strSubject As String
    Dim strMessage As String
     
PROC_START:
   On Error GoTo PROC_ERROR
   
PROC_MAIN:
   
    'Put on hourglass
    DoCmd.Hourglass True

    'Set parameters for email: recipient name, recipient email, Subject, and Message
    strRecipient = Forms!Formname!txtRecipient
    strEmail = Forms!Formname!txtEmail
    strSubject = Forms!Formname!txtSubject
    strMessage = Forms!Formname!txtMessage
            
    'Create a new instance of an Outlook Application object
    Set olApp = New Outlook.Application
    Set olnamespace = olApp.GetNamespace("MAPI")
    Set olMail = olApp.CreateItem(olMailItem)
                
        With olMail
                
            'Email Details
            .To = strEmail
            '.BCC = populate this if you want someone else copied in to the email
            .Subject = strSubject
            .Body = vbCrLf & "Dear " & strRecipient & "," & vbCrLf & vbCrLf & strSubject
            .Importance = olImportanceNormal ' You can change the importance of the email here
            .ReadReceiptRequested = True 'Sends a confirmation when recipient reads email
            .DeleteAfterSubmit = True 'Deletes from sent Items once email is sent
            '.SentOnBehalfOfName = use this if you want to send from a communal outlook account
            '.Attachments.Add Specify a filename here if you want to add attachments
            .Display 'This will let you display the email
            '.Send When you are happy with your code remove the comment and this line will enable the email to be sent automatically
                
            'Here you could keep a record of every email sent in an audit table
            strDeliveryDate = Format(Now(), "dd/mm/yyyy hh:mm:ss")
            strSQL = "Insert into tblEmailHistory values ('" & strEmail & "', '" & strDeliveryDate & "', '" & strRecipient & "','" & strMessage & "', ' ');"
            MsgBox strSQL
            DoCmd.RunSQL (strSQL)
            
        End With
        
PROC_EXIT:
    On Error Resume Next
    DoCmd.Hourglass False
    Set olApp = Nothing
    Set olnamespace = Nothing
    Set olMail = Nothing
 
PROC_ERROR:
    If Err = -2147467259 Then
        MsgBox "You have exceeded the storage limit on your mail box. Please delete some items before clicking OK", vbOKOnly
        Resume
    End If
    
    If Err = 2501 Then
        MsgBox "You have attempted to cancel the output of the emails." & vbCrLf & _
            "This will cause major problems." & vbCrLf & _
            "Please be Patient"
        Resume
    End If
    MsgBox Err.Number & " " & Err.Description
    Resume PROC_EXIT
   
End Sub

When you become more familiar with the code you can get it to do a lot more.

Hope that this helps.

J.



J.

Thanks for your help.

Amy
 
reclusivemonkey said:
The first thing I would suggest is using the addressbook in Outlook. How applicable this is to your situation depends on the number of differing mass mailouts you require. I would think that you should already have most of your contacts already in here. Then its simply a case of adding a "mailout" then adding the relevant contacts to this list. Now if the mass mailout is going to be different every time, then this might not be the best solution. However, doing it this way, if possible, negates the need for a database at all. Let me know what you think of that; if its not viable, you can indeed develop a contacts database (the built in access wizard can help you do this), then you can use one of the many suggested code snippets on the forum.

I am not too familiar with Outlook as I use GroupWise at work, but I seem to remember its pretty simple. I am assuming you are part of a small company and don't have any great tech resources, in which case I would definitely say the KISS (Keep It Simple, Stupid) principal is worth remembering!

Reclusive Monkey,

Thanks for your help.

Amy
 

Users who are viewing this thread

Back
Top Bottom