【问题标题】:Save hyperlinked files to a folder vba将超链接文件保存到文件夹 vba
【发布时间】:2016-02-17 20:59:38
【问题描述】:

我有一个零件数据库,我们一直在使用 Access 2010 附件功能将 PDF 附加到每个零件号。我有一些工作代码可以完成我想做的事情,即查询给定的零件列表并将附加的 PDF 文件保存到文件夹中。我现在将 [PDF] 列更改为超链接列,因为我担心我最终会超过 3GB 的限制。

有没有办法可以修改此代码以使用超链接字段而不是附件类型字段?

这里的最终目标是为我们的客户制作包含所有部分文档 (PDF) 的 CD。

Private Sub Command32_Click()
'this creates a folder for me
If Dir([filePath] & [newFolder], vbDirectory) = "" Then
MkDir [filePath] & [newFolder]
Else

MsgBox ("Folder:" & " " & [newFolder] & " " & "already Exists")
Exit Sub
End If

'code to loop through present list and save attached files to the new folder

Dim db As DAO.Database
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2

Set db = CurrentDb
Set rsParent = Me.Recordset

With rsParent
.MoveFirst 'This ensures that regardless of your current record, the loop will start with the first record

Do While Not .EOF

Set rsChild = rsParent.Fields("pdf").Value

    With rsChild
    Do While Not .EOF
        If rsChild.RecordCount <> 0 Then
            rsChild.OpenRecordset
            rsChild.Fields("FileData").SaveToFile ([filePath] & [newFolder])
            Me.Refresh
            .MoveNext
     Else
        .MoveNext
     End If
    Loop
  End With

.MoveNext
Loop
End With
Exit_SaveImage:

Exit Sub
' error stuff
Err_SaveImage:
If Err = 3839 Then
    MsgBox ("All Done")
    Resume Next
Else
    MsgBox "There's been an error!", Err.Number, Err.DESCRIPTION
    Resume Exit_SaveImage
End If
End Sub

【问题讨论】:

    标签: vba ms-access pdf hyperlink attachment


    【解决方案1】:

    假设包含您的文件 URL 的字段名为 FileURL ,更改

    rsChild.Fields("FileData").SaveToFile ([filePath] & [newFolder])
    

    Filecopy rsChild.Fields("FileURL"), [filePath] & [newFolder]
    

    注意:将 FileURL 字段定义为包含完整限定文件名的普通字符串,而不是 Hyperlink

    希望对你有帮助

    【讨论】:

    • 我确实尝试了您的建议。我替换了上面的代码行并指出包含超链接的字段现在称为 doc_attachment 并设置为下划线表中的超链接列。现在,当我运行代码时,我在 'Set rsChild = rsParent.Field("Doc_Attachment").Value' 对象不支持此属性或方法上得到错误
    • 1) 您说您的“doc_attachment”字段包含您的超链接。请阅读我上面的预兆。 2) 您不能将记录集 (rsChild) 定义为超链接!请使用您的表格定义编辑您的问题。
    猜你喜欢
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-31
    • 1970-01-01
    • 2013-05-15
    • 2023-03-06
    相关资源
    最近更新 更多