conditional macro at end of merge

S

slickdock

I have a generic MSAccess module that says to Merge
form file with data file. The data is coming across from the MSAccess
database.

I need a condition to chain a macro if it
is needed for the form file. Could I put the macro name in a field
in
the data file, then programatically say to run macro referenced in
DataField[macroname] if DataField[macroname] is not blank? It was
easy in WordPerfect, because I could use the {ChainMacro "x"} command
in the form file, and it would execute that macro after the merge was
complete. I'm trying to find an equivalent in VB.

I experimented with {Macrobutton x} in the form file, but I couldn't
make that work, because upon merging the form file, {Macrobutton}
seems to disappear. And I can't tell it to execute the macrobutton
BEFORE the merge starts, because I need it to execute at the end of
the merge.

I am a beginner at VB, so please go easy on me! But I work well from
examples.
Thanks so much.
 
J

Jean-Guy Marcil

I have a generic MSAccess module that says to Merge
form file with data file. The data is coming across from the MSAccess
database.

I need a condition to chain a macro if it
is needed for the form file. Could I put the macro name in a field
in
the data file, then programatically say to run macro referenced in
DataField[macroname] if DataField[macroname] is not blank? It was
easy in WordPerfect, because I could use the {ChainMacro "x"} command
in the form file, and it would execute that macro after the merge was
complete. I'm trying to find an equivalent in VB.

I experimented with {Macrobutton x} in the form file, but I couldn't
make that work, because upon merging the form file, {Macrobutton}
seems to disappear. And I can't tell it to execute the macrobutton
BEFORE the merge starts, because I need it to execute at the end of
the merge.

I am a beginner at VB, so please go easy on me! But I work well from
examples.

Are you executing the merge from code within Access or manually from Access?
If by code, can you post the relevant code?
 
S

slickdock

I have a generic MSAccess module that says to Merge
form file with data file.  The data is coming across from the MSAccess
database.
I need a condition to chain a macro if it
is needed for the form file.  Could I put the macro name in a field
in
the data file, then programatically say to run macro referenced in
DataField[macroname] if DataField[macroname] is not blank?  It was
easy in WordPerfect, because I could use the {ChainMacro "x"} command
in the form file, and it would execute that macro after the merge was
complete. I'm trying to find an equivalent in VB.
I experimented with {Macrobutton x} in the form file, but I couldn't
make that work, because upon merging the form file, {Macrobutton}
seems to disappear. And I can't tell it to execute the macrobutton
BEFORE the merge starts, because I need it to execute at the end of
the merge.
I am a beginner at VB, so please go easy on me! But I work well from
examples.

Are you executing the merge from code within Access or manually from Access?
If by code, can you post the relevant code?- Hide quoted text -

- Show quoted text -

Thank you for replying. I am executing the merge from within an Access
module. Here it is:

Public Function MergeIt() As Boolean
Dim wd As Object
Dim wdActiveDoc As Object 'RM: Added this to help ensure that
you're
'working on the document you intend to.
Dim wdField As Object 'RM: Note the change in name here to avoid
'ambiguity with the Field object in both
Word and
'Access. As well, I changed the type, since
'(like Word.Application), you have to use
late binding.

Set wd = CreateObject("Word.Application")

' need this or fill in's leave it w/no toolbar:
wd.Visible = True

wd.Application.ScreenUpdating = False

' a prior module has already copied the necessary word form file to k:
\legalper and named it mergform.doc...
Set wdActiveDoc = wd.Documents.Open("K:\legalper\mergform.doc",
False, False, _
False, "", "", False, "", "", 0)

With wdActiveDoc.MailMerge
.Destination = 0
.Execute
End With
wd.Windows("mergform.doc").Activate
wd.ActiveWindow.Close 0

'begin unlink
wd.Selection.WholeStory
wd.Selection.Fields.unlink
wd.Selection.HomeKey 6
wd.Visible = True
wd.Application.ScreenUpdating = True
 
J

Jean-Guy Marcil

:

Thank you for replying. I am executing the merge from within an Access
module. Here it is:

Public Function MergeIt() As Boolean
Dim wd As Object
Dim wdActiveDoc As Object 'RM: Added this to help ensure that
you're
'working on the document you intend to.
Dim wdField As Object 'RM: Note the change in name here to avoid
'ambiguity with the Field object in both
Word and
'Access. As well, I changed the type, since
'(like Word.Application), you have to use
late binding.

Set wd = CreateObject("Word.Application")

' need this or fill in's leave it w/no toolbar:
wd.Visible = True

wd.Application.ScreenUpdating = False

' a prior module has already copied the necessary word form file to k:
\legalper and named it mergform.doc...
Set wdActiveDoc = wd.Documents.Open("K:\legalper\mergform.doc",
False, False, _
False, "", "", False, "", "", 0)

With wdActiveDoc.MailMerge
.Destination = 0
.Execute
End With
wd.Windows("mergform.doc").Activate
wd.ActiveWindow.Close 0

'begin unlink
wd.Selection.WholeStory
wd.Selection.Fields.unlink
wd.Selection.HomeKey 6
wd.Visible = True
wd.Application.ScreenUpdating = True

Would the macro to be executed after the merge be a macro that is part of
the Word Document Project or a macro in Access?
What would this macro do (in a few words...)?
 
S

slickdock

:

<snip>













Would the macro to be executed after the merge be a macro that is part of
the Word Document Project or a macro in Access?
What would this macro do (in a few words...)?- Hide quoted text -

- Show quoted text -

The macro would be executed in word, it would be in their normal.dot.
The macro(s) are different, and depend on the form file: Formfile1
needs to execute macro1. Formfile2 needs to execute macro2, etc.
They do various and assorted things, not explainable in a few words,
and nothing is consistent between them.
 
J

Jean-Guy Marcil

:

The macro would be executed in word, it would be in their normal.dot.
The macro(s) are different, and depend on the form file: Formfile1
needs to execute macro1. Formfile2 needs to execute macro2, etc.
They do various and assorted things, not explainable in a few words,
and nothing is consistent between them.

You could try to add code like the following at the end of your macro, just
befeore the
wd.Application.ScreenUpdating = True
line.

Const strMacroPrefix As String = "Normal.Module_Name."
Dim strMacroSuffix As String

strMacroSuffix = "Get_Sub_Name_from_Access_Field"

wd.Application.Run strMacroPrefix & strMacroSuffix
 
S

slickdock

Would the macro to be executed after the merge be a macro that is part of
You could try to add code like the following at the end of your macro, just
befeore the
   wd.Application.ScreenUpdating = True
line.

Const strMacroPrefix As String = "Normal.Module_Name."
Dim strMacroSuffix As String

strMacroSuffix = "Get_Sub_Name_from_Access_Field"

wd.Application.Run strMacroPrefix & strMacroSuffix

I'm sorry I'm not up to that skill level. 2 questions:

1. How do I know what the "Normal.Module_Name." is?

2. How do I tell it to "Get_Sub_Name_from_Access_Field"? I'm assuming
this means I store the macro name in a field in the access record.
That's not a problem. But how do I tell VB to obtain the contents of
that field?
 
S

slickdock

I'm sorry I'm not up to that skill level. 2 questions:

1. How do I know what the "Normal.Module_Name." is?

2. How do I tell it to "Get_Sub_Name_from_Access_Field"? I'm assuming
this means I store the macro name in a field in the access record.
That's not a problem. But how do I tell VB to obtain the contents of
that field?- Hide quoted text -

- Show quoted text -

Have you given up on me? I hope not.... :)
 
J

Jean-Guy Marcil

:


Get it from your template.
You can name the project and the module if you want to.
Or use the default value Word uses when you created them.

Well, this is AccesS VBA, so I can't really help you with that.
Have you given up on me? I hope not.... :)

Sorry, but since I started working 9 to 5 for a company, I cannot
participate as much as I used to.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top