Passing Values to a module

G

Guest

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
 
G

Guest

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.
 
P

pietlinden

..Subject = "**RECALL** - **NO ** - ** CDE ** - ** NO **"

..Subject = Me.Controls("txtRecall") & "-" & me.controls("txtNo") & "-"
& me.controls("txtCDE") & Me.Controls("txtNo")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top