tfisher9180
New member
- Local time
- Today, 01:26
- Joined
- Jan 7, 2016
- Messages
- 2
Hello,
I have an attachment field in one of my tables, the name of the attachment field is "Printout". I want to use the SaveToFile method so that I can temporarily save the file and reference it using CDO Message AddAttachment. I think I've almost got it, but in my email it's attaching a blank file with "noname", what am I doing wrong here? This is the code:
And then I didn't attach all of my CDO code because it has the schema links and I'm new to the forum and can't post links. The CDO code works just fine though.
I have an attachment field in one of my tables, the name of the attachment field is "Printout". I want to use the SaveToFile method so that I can temporarily save the file and reference it using CDO Message AddAttachment. I think I've almost got it, but in my email it's attaching a blank file with "noname", what am I doing wrong here? This is the code:
Code:
Public Function SaveAttachments(strPath As String, Optional strPattern As String = "*.*") As Long
Dim dbs As DAO.Database
Dim rst As DAO.Recordset2
Dim rsA As DAO.Recordset2
Dim fld As DAO.Field2
Dim strFullPath As String
Dim sql As String
Set dbs = CurrentDb()
sql = "SELECT Printout FROM Grade"
Set rst = dbs.OpenRecordset(sql, dbOpenDynaset)
Set fld = rst("Printout")
Do While Not rst.EOF
Set rsA = fld.Value
Do While Not rsA.EOF
If rsA("FileName") Like strPattern Then
strFullPath = strPath & "\" & rsA("FileName")
If Dir(strFullPath) = "" Then
rsA("FileData").SaveToFile strFullPath
SaveAttachments = SaveAttachments + 1
End If
rsA.MoveNext
Loop
rsA.Close
rst.MoveNext
Loop
rst.Close
dbs.Close
Set fld = Nothing
Set rsA = Nothing
Set rst = Nothing
Set dbs = Nothing
End Function
And then I didn't attach all of my CDO code because it has the schema links and I'm new to the forum and can't post links. The CDO code works just fine though.
Code:
cdomsg.AddAttachment strFullPath