我有一个零件数据库,我们一直在使用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
答案 0 :(得分:0)
假设包含您的文件网址的字段名为FileURL
,请更改
rsChild.Fields("FileData").SaveToFile ([filePath] & [newFolder])
到
Filecopy rsChild.Fields("FileURL"), [filePath] & [newFolder]
注意:将Hyperlink
字段定义为包含完整限定文件名的普通字符串,而不是FileURL
。
希望这有帮助