Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / October 2007

Tip: Looking for answers? Try searching our database.

Passing Values to a module

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GLT - 31 Oct 2007 06:03 GMT
Hi,

I have some code that I got from Microsoft that I can use to send an
automatic email from access - this code is iserted into a module and is
called from a sub.

I would like the module when it is called by the sub, to pick up some of the
fields from a form and then email the details out.

So to summarise, I click a button on my form, it executes VBA code which
calls the module.

How do I get the module to pick up the contents of these fields so that it
can be emailed?

In the code below, the subject line contains the fileds that I would like to
display from the form (ie. "**RECALL** - **NO ** - **  CDE ** - **  NO **")

The code that I got from the MS website is as follows:

Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
   Dim objOutlook As Outlook.Application
   Dim objOutlookMsg As Outlook.MailItem
   Dim objOutlookRecip As Outlook.Recipient
   Dim objOutlookAttach As Outlook.Attachment
   
     ' Create the Outlook session.
     Set objOutlook = CreateObject("Outlook.Application")

   ' Create the message.
     Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

     With objOutlookMsg
   ' Add the To recipient(s) to the message.
     Set objOutlookRecip = .Recipients.Add("Bill Gates")
         objOutlookRecip.Type = olTo

   ' Add the CC recipient(s) to the message.
     Set objOutlookRecip = .Recipients.Add("Admin")
         objOutlookRecip.Type = olCC

   ' Add the BCC recipient(s) to the message.
     'Set objOutlookRecip = .Recipients.Add("")
         'objOutlookRecip.Type = olBCC

   ' Set the Subject, Body, and Importance of the message.
        .Subject = "**RECALL** - **NO ** - **  CDE ** - **  NO **"
        .Body = "Blah Blah Blah"
        .Importance = olImportanceHigh  'High importance

   ' Add attachments to the message.
        If Not IsMissing(AttachmentPath) Then
               Set objOutlookAttach = .Attachments.Add(AttachmentPath)
        End If

   ' Resolve each Recipient's name.
        For Each objOutlookRecip In .Recipients
                 objOutlookRecip.Resolve
            Next

  ' Should we display the message before sending?
            If DisplayMsg Then
                .Display
            Else
                .Save
                .Send
            End If
         End With
         Set objOutlook = Nothing
     End Sub
Timbo - 31 Oct 2007 11:48 GMT
If the code is on your form you can refer to each control on the form in the
following way.

Me.ControlName

If the code is not on your form then use:

Forms!FormName!ControlName

In both cases as we have not specified the property we want to read it will
read the default property. If you want to read a different property than
simply add on the name of the property to the above i.e. .PropertyName

Tim.

> Hi,
>
[quoted text clipped - 66 lines]
>           Set objOutlook = Nothing
>       End Sub
pietlinden@hotmail.com - 01 Nov 2007 00:39 GMT
.Subject = "**RECALL** - **NO ** - **  CDE ** - **  NO **"

.Subject = Me.Controls("txtRecall") & "-" & me.controls("txtNo") & "-"
& me.controls("txtCDE") & Me.Controls("txtNo")
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.