我正在开发一个小项目,我需要能够使用存储在Access 2016数据库中的数据填充Word 2016表单。为此,我创建了一个带有按钮(保存)的表单(Customers)。单击该按钮时,表单中的数据将保存到表(Customers)并发送到Word表单。这是我按照Techrepublic.
的说明操作的代码Private Sub cmdPrint_Click()
'Print customer slip for current customer.
Dim appWord As Word.Application
Dim doc As Word.Document
'Avoid error 429, when Word isn't open.
On Error Resume Next
Err.Clear
'Set appWord object variable to running instance of Word.
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn't open, create a new instance of Word.
Set appWord = New Word.Application
End If
Set doc = appWord.Documents.Open("E:\Usuarios\Acrocephalus\Daniel\Projectes\AnemaDB\ProgramaControlDDD2015.docx", , True)
With doc
.FormFields("fldIDClient").Result = Me!IDClient
.FormFields("fldNomLocal").Result = Me!NomLocal
.FormFields("fldNomFiscal").Result = Me!NomFiscal
.FormFields("fldNIF_CIF").Result = Me!NIF_CIF
.FormFields("fldTipusVia").Result = Me!TipusVia
.FormFields("fldAdreca").Result = Me!Adreca
.FormFields("fldCP").Result = Me!CP
.FormFields("fldMunicipi").Result = Me!Municipi
.FormFields("fldProvincia").Result = Me!Provincia
.FormFields("fldFix").Result = Me!Fix
.FormFields("fldMobile").Result = Me!Mobile
.FormFields("fldemail").Result = Me!email
.Visible = True
.Activate
End With
Set doc = Nothing
Set appWord = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
End Sub
然而,当我填写数据并点击按钮时,我有3个问题:
有人可以帮忙吗? 谢谢!
达尼
答案 0 :(得分:1)
您是否在VBA中使用了正确的参考文献?
在VBA编辑器上按工具&gt;参考,并在Microsoft Work xx.0对象库
之前进行检查