我之前发布了一个关于邮件合并操作的问题,我将参数直接添加到邮件合并中:
sqlstatement:="SELECT * FROM [Customer Data]
WHERE [Customer Data].[Status]='Complete'
AND [Customer Data].[CompletedBy] = '" & userID & "'
AND [Customer Data].[Date Completed] Between #" & date1 & "#
And #" & date2 & "#;"
评论中建议这是一个坏主意;我知道数据库操作应该避免这种情况,因为可以利用它来运行更改数据库的代码,但是对于打印邮件合并来说这是一个坏主意吗?这会导致现实世界的漏洞利用吗?似乎 SQL 只选择将填充到字母合并上的内容。为了正确填充邮件合并,还有哪些其他选项可用?
Set objword = GetObject("S:\Share with Bob\Administration 2010 Repository\Mail Merge\AIB.doc")
'Make Word visible
objword.Application.Visible = True
'Set the mail merge data source to the database
objword.MailMerge.OpenDataSource _
Name:="C:\Database.mdb", _
LinkToSource:=True, _
Connection:="[TABLE - TRANSACTION]", _
sqlstatement:="SELECT * FROM [TABLE - TRANSACTION] ORDER BY [TABLE - TRANSACTION].[Transaction Number]"
'Execute the mail merge
objword.MailMerge.Destination = wdSendToNewDocument
objword.MailMerge.Execute
objword.Application.Options.PrintBackground = False
'Print a copy
objword.Application.ActiveDocument.PrintOut
'Close Word and do not save the changes
objword.Application.Quit SaveChanges:=wdDoNotSaveChanges
'Clear the objWord Object
Set objword = Nothing