【发布时间】:2011-11-11 05:43:39
【问题描述】:
我正在将数据库从访问转换为 sql 后端访问前端。该数据库嵌入了 pdf 文档,这些文档最终被 SQL Server 的数据导入工具存储为 [image] 数据。
我的问题是我希望用户能够通过单击在 access 中创建的报告中的 pdf 图标来打开 pdf 文件。
这可以用 VBA 完成还是有更简单的方法?我完全不知道如何做到这一点。
感谢您的回答!
我编辑了 BlobToFile 函数以去除 ole 标头,因为 adobe 无法读取文件(evince 可以,mac 预览也可以)
我能够像这样做我想做的事:
Private Sub PDFDocument_Click()
Call BlobToFile("C:\db\MyPDFFile.pdf", Me.PDFDocument)
If Dir("C:\db\MyPDFFile.pdf") <> "" Then
FollowHyperlink ("C:\db\MyPDFFile.pdf")
End If
End Sub
'Function: BlobToFile - Extracts the data in a binary field to a disk file.
'Parameter: strFile - Full path and filename of the destination file.
'Parameter: Field - The field containing the blob.
'Return: The length of the data extracted.
Public Function BlobToFile(strFile As String, ByRef Field As Object) As Long
On Error GoTo BlobToFileError
Dim nFileNum As Integer
Dim abytData() As Byte
Dim abytParsedData() As Byte
Dim copyOn As Boolean
Dim copyIndex As Long
BlobToFile = 0
nFileNum = FreeFile
copyOn = False
copyIndex = 0
Open strFile For Binary Access Write As nFileNum
abytData = Field
ReDim abytParsedData(UBound(abytData))
For i = LBound(abytData) To UBound(abytData) - 1
If copyOn = False Then
If Chr(abytData(i)) = "%" And Chr(abytData(i + 1)) = "P" And Chr(abytData(i + 2)) = "D" And Chr(abytData(i + 3)) = "F" Then
copyOn = True
End If
End If
If copyOn = True Then
abytParsedData(copyIndex) = abytData(i)
copyIndex = copyIndex + 1
End If
Next
Put #nFileNum, , abytParsedData
BlobToFile = LOF(nFileNum)
BlobToFileExit:
If nFileNum > 0 Then Close nFileNum
Exit Function
BlobToFileError:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, _
"Error writing file in BlobToFile"
BlobToFile = 0
Resume BlobToFileExit
End Function
【问题讨论】:
-
重复问题是 StackOverflow 的一大禁忌。这不是一个传统的论坛。我建议你删除你的另一个问题:stackoverflow.com/questions/8072133/…
标签: sql-server ms-access vba