我正在构建一个数据库来存放word文档和数据。在此表中附有word文档的副本。
如何使用VBA从Field1(默认名称)引用和打开附件(word文档)的副本?
我已尝试使用DAO Recordset,但一直遇到错误。关于附件的对象引用文档几乎没有帮助。
如果需要其他信息,请与我们联系。谢谢!
$sort
答案 0 :(得分:1)
感谢大家的帮助。
根据评论,我能够通过保存和打开临时文件进行处理来解决问题。
Private Sub Field1_AfterUpdate()
'Declarations
'Access-Related
Dim Active_DB As DAO.Database
Dim Active_Q As DAO.QueryDef
Dim Active_RST, parent_RST, child_RST As DAO.Recordset
Dim Active_Field As DAO.Field
'Word-Related
Dim app_Word As Word.Application
Dim Active_DOC As Word.Document
'Varible Declaration
Dim str_Dir, str_FName As String
'Refresh to create record
Forms!entry.Refresh
'Initial Assignments
str_Dir = Environ("Temp") & "\"
Set Active_DB = CurrentDb
Set Active_RST = Forms!entry.Recordset
'Assign Record Set to Current Record
Active_RST.FindFirst "ID =" & Forms!entry.ID.Value
'Assign Field value
Set parent_RST = Active_RST.Fields("Field1").Value
Set Active_Field = parent_RST.FileData
'Create Word Application & document Objects
Set app_Word = CreateObject("Word.application")
If Dir(str_Dir & parent_RST.FileName) = "" Then
'If directory does not exist, create SaveToFiles
'Else open Document
Active_Field.SaveToFile str_Dir & parent_RST.FileName
End If
Set Active_DOC = Documents.Open(str_Dir & parent_RST.FileName)
Contract_Text.Value = str_Dir & parent_RST.FileName
End Sub