C
Carl
Guys
How can I set a value of a field from a specific record
from an Access97 query as varible in Word97?
I don't want to carry out a mail merge (yet) as this value
will be used to source the mail merge (word) template.
This is what I have:
'mailmerge to determine the template to use
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:= _
"\\MELFS004\Position Profiles.mdb" _
, ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="",
WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="QUERY
qryTemplateCreation", _
SQLStatement:="SELECT * FROM
[qryTemplateCreation]", SQLStatement1:=""
'a user form sets the value of the txtPos varible
ActiveDocument.MailMerge.DataSource.QueryString = _
"SELECT [APS_Level] FROM [qryTemplateCreation]
WHERE (([Position_No] = " _
& "'" & txtPosNo & "'))" & ""
With ActiveDocument.MailMerge
'The value determines which template to use
Templte$ = DataSource.DataFields
("[APS_Level]").Value
End With
Path$ = Path$ + Templte$
'Debug.Print Path$
'Open the template
WordBasic.FileNew Template:=Path$, NewTemplate:=0
Debug.Print QryString$
'the real mailmerge
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:= _
"\\MELFS004\Position Profiles.mdb" _
, ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="",
WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="QUERY
qryTemplateCreation", _
SQLStatement:="SELECT * FROM
[qryTemplateCreation]", SQLStatement1:=""
QryString$ = "SELECT * FROM [qryTemplateCreation]
WHERE (([Position_No] =" _
& "'" & txtPosNo & "'))" & ""
ActiveDocument.MailMerge.DataSource.QueryString =
QryString$
'carry out the merge
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
How can I set a value of a field from a specific record
from an Access97 query as varible in Word97?
I don't want to carry out a mail merge (yet) as this value
will be used to source the mail merge (word) template.
This is what I have:
'mailmerge to determine the template to use
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:= _
"\\MELFS004\Position Profiles.mdb" _
, ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="",
WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="QUERY
qryTemplateCreation", _
SQLStatement:="SELECT * FROM
[qryTemplateCreation]", SQLStatement1:=""
'a user form sets the value of the txtPos varible
ActiveDocument.MailMerge.DataSource.QueryString = _
"SELECT [APS_Level] FROM [qryTemplateCreation]
WHERE (([Position_No] = " _
& "'" & txtPosNo & "'))" & ""
With ActiveDocument.MailMerge
'The value determines which template to use
Templte$ = DataSource.DataFields
("[APS_Level]").Value
End With
Path$ = Path$ + Templte$
'Debug.Print Path$
'Open the template
WordBasic.FileNew Template:=Path$, NewTemplate:=0
Debug.Print QryString$
'the real mailmerge
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:= _
"\\MELFS004\Position Profiles.mdb" _
, ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="",
WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="QUERY
qryTemplateCreation", _
SQLStatement:="SELECT * FROM
[qryTemplateCreation]", SQLStatement1:=""
QryString$ = "SELECT * FROM [qryTemplateCreation]
WHERE (([Position_No] =" _
& "'" & txtPosNo & "'))" & ""
ActiveDocument.MailMerge.DataSource.QueryString =
QryString$
'carry out the merge
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With