Question

I need to figure out how to put a code in MS Access vba for attaching all the files in a selected folder. Right now I can do just one from a specific location:

PathLocation = "C:\Test\test.PDF"
If Not IsNull(PathLocation) Then
    txtAttach = PathLocation 
   Set objAttachment = objMailDocument.CREATERICHTEXTITEM("strFileAttachment")
   Set objEmbedObject = objAttachment.EMBEDOBJECT(1454, "", txtAttach, "strFileAttachment")
   End If

But what I really want is to collect all the stuff from the Test folder.

Was it helpful?

Solution

You need the Dir- statement to run through all files in the directory:

Dim PathLocation As String
Dim fileName As String
Dim filePath as String

PathLocation = "C:\Test\"
If Not IsNull(PathLocation) Then
  Set objAttachment = objMailDocument.CREATERICHTEXTITEM("strFileAttachment")
  fileName = Dir$(PathLocation & "*.*", 0)
  Do While fileName <> ""
    filePath = PathLocation & fileName
    Set objEmbedObject = objAttachment.EMBEDOBJECT(1454, "", filePath, "")
    fileName = Dir$()
  Loop
End If

To run through e.g. just PDFs replace the *.* in the code above by *.pdf

OTHER TIPS

Hope this should help,there is an example attached at the end as well.

http://bytes.com/topic/access/insights/916710-select-file-folder-using-filedialog-object

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top