I try to merge word document from ACCESS. Every thing looks good. but because my access database have security set up. so everytime I start to run macro to start mail merge, It pop up a window to ask you userid and password.
I wonder is there any way I could hard code in the VBA code.
My function is:
Function MergeIt()
On Error GoTo ErrorHandler
Dim objWord As Word.Document
Set objWord = GetObject("D:\unfinished project\Investment Agency.doc", "Word.Document"
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Northwind database.
objWord.MailMerge.OpenDataSource _
Name:="D:\unfinished project\TEST Secure Consent.mdb", _
LinkToSource:=False, _
Connection:="QUERY qryLabelQuery", _
SQLStatement:="Select * from `qryLabelQuery`"
' Execute the mail merge.
objWord.MailMerge.Execute
Set objWord = Nothing
ErrorHandler:
MsgBox "Error #" & Err.Number & " occurred. " & Err.Description, vbOKOnly, "Error"
Exit Function
End Function
I wonder in somewhere in objWord.MailMerge.OpenDataSource ,
I could hard code userid and password for that.
Any idea?
I wonder is there any way I could hard code in the VBA code.
My function is:
Function MergeIt()
On Error GoTo ErrorHandler
Dim objWord As Word.Document
Set objWord = GetObject("D:\unfinished project\Investment Agency.doc", "Word.Document"
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Northwind database.
objWord.MailMerge.OpenDataSource _
Name:="D:\unfinished project\TEST Secure Consent.mdb", _
LinkToSource:=False, _
Connection:="QUERY qryLabelQuery", _
SQLStatement:="Select * from `qryLabelQuery`"
' Execute the mail merge.
objWord.MailMerge.Execute
Set objWord = Nothing
ErrorHandler:
MsgBox "Error #" & Err.Number & " occurred. " & Err.Description, vbOKOnly, "Error"
Exit Function
End Function
I wonder in somewhere in objWord.MailMerge.OpenDataSource ,
I could hard code userid and password for that.
Any idea?