简体   繁体   English

使用书签但从表单而不是 tbl 或 qry 访问 Word

[英]Access to Word using bookmarks but from a Form rather than a tbl or qry

Fairly new to access, this might be a really weird way of going about it but here's the situation, I have a form with a certain manager's information on it such as address and email, etc. I want to be able to create a letter with their address populated in the right spot on a Word Document and I've got pretty far I think But I've hit a roadblock.访问相当新,这可能是一种非常奇怪的处理方式,但情况是这样的,我有一个表格,上面有某个经理的信息,例如地址和电子邮件等。我希望能够创建一封信他们的地址填充在 Word 文档的正确位置,我认为我已经走了很远但我遇到了障碍。 I can't figure out how to populate this word document with the address that's on the form, I've tried making a query that spits out the same information as the form but it kept coming back with the我不知道如何使用表单上的地址填充这个 word 文档,我尝试进行一个查询,该查询会吐出与表单相同的信息,但它不断返回

"Run-time error 3061: Too few Parameters. Expected 1" “运行时错误 3061:参数太少。预期为 1”

and the same thing is happening now when I've cut out the middle man and just put an SQL statement in the open recordset command.现在当我去掉中间人并在打开记录集命令中放入一条 SQL 语句时,同样的事情正在发生。

The problem is with Line 12 (Starting Set rs = dbs.OpenRecordset...)问题出在第 12 行(起始集 rs = dbs.OpenRecordset...)

Thank you for any light you can shed on this!!感谢您对此的任何启发!!

Private Sub btnManagerLetter_Click()

    Dim wdApp As Word.Application
    Dim wdDoc As Word.Document
    Dim rs As DAO.Recordset
    Dim dbs As DAO.Database
    Dim address As String

    Set dbs = CurrentDb
    Set wdApp = New Word.Application
    Set wdDoc = wdApp.Documents.Open("\\middle\Data\DataBaseWordDocs&Ding\ding\InsCoLtrTemplate.docx")
    Set rs = dbs.OpenRecordset("SELECT * FROM tblManagers WHERE (((tblManagers.ManagerRef) Like Me![ManagerRef]))", dbOpenSnapshot)
        
    wdApp.Visible = True

    wdDoc.Bookmarks("ManagerName").Range.Text = Nz(rs![Manager Name], "")
    address = Nz(rs![Address Line 1], vbNullString)
    address = Append(address, Nz(rs![Address Line 2], vbNullString))
    address = Append(address, Nz(rs![Town], vbNullString))
    address = Append(address, Nz(rs![County], vbNullString))
    address = Append(address, Nz(rs![Post Code], vbNullString))
    
    wdDoc.Bookmarks("Address").Range.Text = address

End Sub

Must concatenate Me![ManagerRef] .必须连接Me![ManagerRef] All those parens are not needed.不需要所有这些括号。 LIKE without wildcard might as well be = sign.没有通配符的 LIKE 也可能是 = 符号。 If ManagerRef is a text type field, will need delimiters.如果 ManagerRef 是文本类型字段,则需要分隔符。

Set rs = dbs.OpenRecordset("SELECT * FROM tblManagers WHERE ManagerRef ='" &  Me![ManagerRef] & "'", dbOpenSnapshot)

Otherwise, learn about using embedded parameters:否则,了解使用嵌入式参数:
How do I use parameters in VBA in the different contexts in Microsoft Access? 如何在 Microsoft Access 的不同上下文中使用 VBA 中的参数?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM