Norman,
Here is some VBA that will work if you are using Outlook Automation to send
your emails. It uses of the code found at:
http://www.mvps.org/access/api/api0001.htm
This code makes use of Windows API calls to allow file selection and
requires no additional OCX file or dialog control (we don't recommend these,
as they are prone to versioning and licensing problems). Don't worry
about the API calls; this code is essentially "plug 'n play".
So, first: create a new Module and name it FileHandling. Then copy all of
the code from that link into the module.
Second: copy the following function into the same module (put it at the
bottom).
Function GetAttachments(strIn As String) As String
'Calls GetOpenFileName dialog and allows user to
'select attachments for an email
Dim strFilter As String
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "RTF Documents (*.rtf)", "*.RTF")
strFilter = ahtAddFilterItem(strFilter, "Excel Worksheet Files (*.xls)",
"*.XLS")
strFilter = ahtAddFilterItem(strFilter, _
"Access Database(*.mdb;*.mda;*.mde;*.mdw) ", _
"*.mdb; *.mda; *.mde; *.mdw")
strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
GetAttachments = ahtCommonFileOpenSave(Filter:=strFilter, _
OpenFile:=True, _
DialogTitle:=strIn, _
Flags:=ahtOFN_HIDEREADONLY)
End Function
Last: in the Click event of a command button on your form, insert the
following code
Dim oApp As Outlook.Application
Dim objNewMail As Outlook.MailItem
Dim objOutlookAttach As Outlook.Attachment
Dim strAtt As String
Set oApp = New Outlook.Application
Set objNewMail = oApp.CreateItem(olMailItem)
With objNewMail
.To = "(e-mail address removed)"
.Subject = "Test subject"
.Body = "Your text message here."
' Select files
Do
strAtt = GetAttachments("Select a file - click Cancel when done")
If strAtt <> "" Then
Set objOutlookAttach = .Attachments.Add(strAtt)
Else
Exit Do
End If
Loop
' End selection of files to attach
.Save
.Send
End With
hth,