Launching a module from a macro

  • Thread starter Thread starter susanmgarrett
  • Start date Start date
S

susanmgarrett

Goal: In Access 2000, To use an unbound field to choose a record from
a query, the data of which is merged into a launched copy of Word
2000.

I'm using the "How to Use Automation to Run Word 2000 Mail Merge from
Access" instructions from MS Knowledgebase, but I've never used a
module before.

The macro opens the select form and chooses the correct record when
data is input into the unbound field. Buttons work perfectly.

The module launches perfectly when I type ?MergeIt() in the immediate
window of the module.

How do I launch the module from within the macro so that after the
record is selected, Word will launch the document merge as contained
in the module?

Thank you for your assistance. Specifics below.

Regards
Susan M. Garrett
____________________________
Macro: conmha
1. Open Dialog
Action: Openform
FormName: Contract - Metal Hurlant Artist

Condition: Not IsLoaded("Contract - Metal Hurlant Artist")
Cancel Event

2. Close Dialog
Action: Close
Object Type: Form
Object Name: Contract - Metal Hurlant Artist

3. OKbutton
Action: SetValue

4. Cancelbutton
Action: Close
Object Type: Form
Object Name: Contract - Metal Hurlant Artist


Module: Mergewordmhaconart

Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject
("C:\humanoids\docs\contractmhart.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Humanoids database.
objWord.MailMerge.OpenDataSource _
Name:="C:\humanoids\humanoids.mdb", _
LinkToSource:=True, _
Connection:="QUERY Query - ContractMHArt", _
SQLStatement:="SELECT * FROM [Query - ContractMHArt]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
 
Thank you for your quick reply!

When I placed the following:

Action: RunCode
Function: MergeIt()

As the last action in the this macros subsection:

It lauched beautifully! My form came up, the contact # was entered,
and access launched Word.

Unfortunately, it launched both the Word template and the final merged
document. Is there a Close argument I can put in either the Macro or
the Module that will close the Word document and leave open the merged
document and where would I place the code?

Thank you for your help! It's most appreciated.

Regards

Susan M. Garrett













Nikos Yannacopoulos said:
In your macro use action RunCode, argument MergeIt().

HTH,
Nikos
susanmgarrett said:
Goal: In Access 2000, To use an unbound field to choose a record from
a query, the data of which is merged into a launched copy of Word
2000.

I'm using the "How to Use Automation to Run Word 2000 Mail Merge from
Access" instructions from MS Knowledgebase, but I've never used a
module before.

The macro opens the select form and chooses the correct record when
data is input into the unbound field. Buttons work perfectly.

The module launches perfectly when I type ?MergeIt() in the immediate
window of the module.

How do I launch the module from within the macro so that after the
record is selected, Word will launch the document merge as contained
in the module?

Thank you for your assistance. Specifics below.

Regards
Susan M. Garrett
____________________________
Macro: conmha
1. Open Dialog
Action: Openform
FormName: Contract - Metal Hurlant Artist

Condition: Not IsLoaded("Contract - Metal Hurlant Artist")
Cancel Event

2. Close Dialog
Action: Close
Object Type: Form
Object Name: Contract - Metal Hurlant Artist

3. OKbutton
Action: SetValue

4. Cancelbutton
Action: Close
Object Type: Form
Object Name: Contract - Metal Hurlant Artist


Module: Mergewordmhaconart

Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject
("C:\humanoids\docs\contractmhart.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Humanoids database.
objWord.MailMerge.OpenDataSource _
Name:="C:\humanoids\humanoids.mdb", _
LinkToSource:=True, _
Connection:="QUERY Query - ContractMHArt", _
SQLStatement:="SELECT * FROM [Query - ContractMHArt]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
 
Susan,

Not sure you can close a document in another application from a macro; I
suspect it could be done with VB code but, to be honest, I have no idea how.
I think you stand a pretty good chance that someone else will, though. I
would suggest that, if you don't get an answer in this thread, you should
make a mew posting on this particular question.

Regards,
Nikos

susanmgarrett said:
Thank you for your quick reply!

When I placed the following:

Action: RunCode
Function: MergeIt()

As the last action in the this macros subsection:

It lauched beautifully! My form came up, the contact # was entered,
and access launched Word.

Unfortunately, it launched both the Word template and the final merged
document. Is there a Close argument I can put in either the Macro or
the Module that will close the Word document and leave open the merged
document and where would I place the code?

Thank you for your help! It's most appreciated.

Regards

Susan M. Garrett













"Nikos Yannacopoulos" <[email protected]> wrote in message
In your macro use action RunCode, argument MergeIt().

HTH,
Nikos
susanmgarrett said:
Goal: In Access 2000, To use an unbound field to choose a record from
a query, the data of which is merged into a launched copy of Word
2000.

I'm using the "How to Use Automation to Run Word 2000 Mail Merge from
Access" instructions from MS Knowledgebase, but I've never used a
module before.

The macro opens the select form and chooses the correct record when
data is input into the unbound field. Buttons work perfectly.

The module launches perfectly when I type ?MergeIt() in the immediate
window of the module.

How do I launch the module from within the macro so that after the
record is selected, Word will launch the document merge as contained
in the module?

Thank you for your assistance. Specifics below.

Regards
Susan M. Garrett
____________________________
Macro: conmha
1. Open Dialog
Action: Openform
FormName: Contract - Metal Hurlant Artist

Condition: Not IsLoaded("Contract - Metal Hurlant Artist")
Cancel Event

2. Close Dialog
Action: Close
Object Type: Form
Object Name: Contract - Metal Hurlant Artist

3. OKbutton
Action: SetValue

4. Cancelbutton
Action: Close
Object Type: Form
Object Name: Contract - Metal Hurlant Artist


Module: Mergewordmhaconart

Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject
("C:\humanoids\docs\contractmhart.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Humanoids database.
objWord.MailMerge.OpenDataSource _
Name:="C:\humanoids\humanoids.mdb", _
LinkToSource:=True, _
Connection:="QUERY Query - ContractMHArt", _
SQLStatement:="SELECT * FROM [Query - ContractMHArt]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
 
Back
Top