문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top