M
muyBN
As a side issue, when I sign in here to post a question, I designate the
option of the system remembering my user name and password, but I always have
to put in my password. Does anyone know what's up with that?
I have a macro that connects a Word document to an Access query then shows
the last fields in the query as merge fields in the document. However, when
the macro is running, it prompts me for the database name, even though it's
already written in the code (see code sample below). If someone can suggest
why this happens and how to correct the code (or the .odc or .dsn settings as
applicable) so that it connects to the database without a prompt, I'd
appreciate it.
With ActiveDocument
.MailMerge.MainDocumentType = wdFormLetters
.MailMerge.OpenDataSource Name:="path\ODCfile.odc" _
, ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", WritePasswordDocument:="",
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:="Provider=MSDASQL.1;Persist Security
Info=False;User ID=b;Extended Properties=""DBQ=path\DB.mdb;" & _
"DefaultDir=path;Driver={Microsoft Access Driver
(*.mdb)};DriverId=25;FIL=MS Access;" & _
"FILEDSN=C:\Program Files\Common Files\ODBC\Data
Sources\query." _
, SQLStatement:="SELECT * FROM `query`",
SQLStatement1:="", SubType:=wdMergeSubTypeOther
.MailMerge.EditMainDocument
.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField,
Text:="""dbField"""
.MailMerge.DataSource.ActiveRecord = wdLastRecord
.MailMerge.ViewMailMergeFieldCodes = wdToggle
End With
option of the system remembering my user name and password, but I always have
to put in my password. Does anyone know what's up with that?
I have a macro that connects a Word document to an Access query then shows
the last fields in the query as merge fields in the document. However, when
the macro is running, it prompts me for the database name, even though it's
already written in the code (see code sample below). If someone can suggest
why this happens and how to correct the code (or the .odc or .dsn settings as
applicable) so that it connects to the database without a prompt, I'd
appreciate it.
With ActiveDocument
.MailMerge.MainDocumentType = wdFormLetters
.MailMerge.OpenDataSource Name:="path\ODCfile.odc" _
, ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", WritePasswordDocument:="",
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:="Provider=MSDASQL.1;Persist Security
Info=False;User ID=b;Extended Properties=""DBQ=path\DB.mdb;" & _
"DefaultDir=path;Driver={Microsoft Access Driver
(*.mdb)};DriverId=25;FIL=MS Access;" & _
"FILEDSN=C:\Program Files\Common Files\ODBC\Data
Sources\query." _
, SQLStatement:="SELECT * FROM `query`",
SQLStatement1:="", SubType:=wdMergeSubTypeOther
.MailMerge.EditMainDocument
.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField,
Text:="""dbField"""
.MailMerge.DataSource.ActiveRecord = wdLastRecord
.MailMerge.ViewMailMergeFieldCodes = wdToggle
End With