Selecting multiple files and send them via email??

  • Thread starter Thread starter Norman F
  • Start date Start date
N

Norman F

Hi there,

I have a database form that mimics the layout of an
outlook form.
It works ok, when I send one email at the time.

How can I select multiple files from this access (2K) form
either useing the file dialog or else (store /attache the
files)or(store the directory name,and file name in array??)

I don't know,
any imput is much appreciated.

kind regards
Norman
 
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,
 
Cheryl
thanks for the hint.
I appriciate very much.

regards
Norman
-----Original Message-----
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
 
Back
Top