ardy
Registered User.
- Local time
- Yesterday, 22:37
- Joined
- Sep 24, 2012
- Messages
- 98
Hello All:
I have an applet in Access(2007). The applet logs calls and enables users to attach files to the call and if they choose, send an e-mail out. Not a VB programmer but I understand it. More of a spaghetti programmer.
These are my issues…….
1. Need to be able to attach to outlook all files saved in the strPath. So the code enables users to save one attachment to a path described in srtPath. I want to be able to save all files as attachment to an e-mail.
2. Need to be able to save more than one file to srtPath directory. users might attach more than a single file to the table. the current code only saves one of the files to the strPath. i want to save all of the files.
3. Last but not least delete all files under srtPath directory after sending the e-mail ( I am sure IO can figure this out – currently not in the code.)
-------------------------------------
The code that sends the e-mail
The function to save the file to local drive
I have an applet in Access(2007). The applet logs calls and enables users to attach files to the call and if they choose, send an e-mail out. Not a VB programmer but I understand it. More of a spaghetti programmer.
These are my issues…….
1. Need to be able to attach to outlook all files saved in the strPath. So the code enables users to save one attachment to a path described in srtPath. I want to be able to save all files as attachment to an e-mail.
2. Need to be able to save more than one file to srtPath directory. users might attach more than a single file to the table. the current code only saves one of the files to the strPath. i want to save all of the files.
3. Last but not least delete all files under srtPath directory after sending the e-mail ( I am sure IO can figure this out – currently not in the code.)
-------------------------------------
The code that sends the e-mail
Code:
Private Sub Form_Close()
' Attaching and sending e-mail
Dim N As String
Dim S As String
N = Forms!Contact_Calls_NRSS!Lbl_Notes
S = Forms!Contact_Calls_NRSS!Lbl_Subject
' Sending E-mail
Set db = CurrentDb
Set rs = db.OpenRecordset("Calls_Tmp")
Do While Not rs.EOF
varEmailAdd = varEmailAdd & rs!E_mailAdd & ";"
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
varEmailAdd = Left(varEmailAdd, Len(varEmailAdd) - 1)
MsgBox "Sending E-mail To The Following E-mail Addresses.." & vbNewLine _
& vbNewLine _
& varEmailAdd & vbNewLine _
& vbNewLine _
& "Please make sure to use GWMP e-mail address in the FROM: in Outlook"
' ---------------------------- Send Email Using Outlook
' Prevent 429 error, if outlook not open
On Error Resume Next
Err.Clear
Set oOutlook = GetObject(, "Outlook.application")
If Err.Number <> 0 Then
Set oOutlook = New Outlook.Application
End If
Set oEmailItem = oOutlook.CreateItem(olMailItem)
With oEmailItem
.To = varEmailAdd
.BCC = ""
.Subject = S
.Body = N
.Attach [B]‘ some how attaching all the files in strPath of the Function(SaveAttachment)[/B]
.Display
End With
Set oEmailItem = Nothing
Set oOutlook = Nothing
DoCmd.Close acForm, "Contact_Calls_NRSS", acSaveYes
End Sub
Code:
Function SaveAttachment()
Dim db As DAO.Database
Dim rst As DAO.Recordset2
Dim rstAttachment As DAO.Recordset2
Dim fld As DAO.Field2
Dim strPath As String
Dim intz As Integer
Dim Directory As String
Dim Root As String
Dim Path As String
Directory = "temp\"
Root = "C:\"
Path = Root & Directory
' check to see if the directory exist
If Len(Dir(Path, vbDirectory)) = 0 Then
MkDir Path
End If
‘ [B]if there are more than 1 attachments, I think this needs to be a loop that saves them all[/B]
Set db = CurrentDb
Set rst = db.OpenRecordset("Attachment", dbOpenDynaset)
rst.FindLast "ID = " & Forms!Attachment_NR!Lbl_AttachID
Set rstAttachment = rst.Fields("Attach").Value
Set fld = rstAttachment.Fields("Filedata")
strPath = Path & rstAttachment.Fields("Filename")
fld.SaveToFile strPath
rstAttachment.Close
rst.Close
Set rstAttachment = Nothing
Set rst = Nothing
Set db = Nothing
DoCmd.Close acForm, "Attachment_NR", acSaveYes
End Function
Last edited: