【发布时间】:2019-01-08 22:16:27
【问题描述】:
我是 Access 新手;我自定义了下面的代码。问题是它打印主键而不是所引用字段的名称。
例如,在一个语句中,我希望在 Word 中打印机构名称,但它从我的表中的一个特定的 rinstitute 中返回主键。
FormFields("txtNQFLevel").Result = Me.NQFLLEVEL我想要另一个表中的这个字段,但在同一个查询中返回字符串值,而不是其相反的主键值
FormFields("txtInstitute").Result = Me.Institute_Name我希望这个字段来自另一个表但在同一个查询中返回字符串值而不是其相反的主键值
Function BursaryContractYear2()
Dim appWord As Word.Application
Dim doc As Word.Document
Dim Path As String
On Error Resume Next
Error.Clear
Path = "C:\Users\Motlatsi Motlhamme\Desktop\FillWordAccess.docx "
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set appWord = New Word.Application
appWord.Visible = True
End If
Set doc = appWord.Documents.Open(Path, , True)
With doc
.FormFields("txtFirstName").Result = Me.FIRST_NAMES
.FormFields("txtSurname").Result = Me.SURNAME
.FormFields("txtNQFLevel").Result = Me.NQFLLEVEL
.FormFields("txtInstitute").Result = Me.Institute_Name
appWord.Visible = True
appWord.Activate
End With
Set doc = Nothing
Set appWord = Nothing
End Function
【问题讨论】:
-
一般情况下最好不要使用
On Error Resume Next...,尤其是在解决问题时。您是在告诉 VBA 忽略所有错误。 -
您没有提供足够的信息。
Me.是什么?是表格吗?
标签: vba ms-access ms-word office-interop