查找与ms访问中的字段值匹配的文件名

时间:2013-09-16 07:55:47

标签: forms vba ms-access match filenames

我有一个包含2个字段'name'和'date'

的表

我有一个文件夹,其中包含一些在文件名中包含名称和日期的文件,如下所示: Andrew Dost_12Sep2013 04-59-58 PM_4.docx

我的表单应该能够遍历这些文件,并获取与表单的名称和日期字段匹配的文件,并将其附加到电子邮件中。

任何大师能帮助我吗?

由于

1 个答案:

答案 0 :(得分:0)

您应该看“Dir功能示例”


set rst=openrecordset("TaleWith2fields")

while not rst.eof ' cycle through rows

  MyPath = rst![name] & "_" & rst![date] & "*.docx"
  MyName = Dir(MyPath)    ' Retrieve the first entry of matched files

  Do While MyName <> ""    ' Start the loop of matched files
      ' DO what you want with file named MyName
      '          

      MyName = Dir ' next matched file
  Loop             ' next matched file

  rst.movenext ' next row in table   
wend               ' next row in table