Group:  Microsoft Word ยป microsoft.public.word.mailmerge.fields
Thread: MsgBox during merge

Geek News

MsgBox during merge
"Kathy Webster" <slickdock[ at ]yahoo.com> 5/9/2007 11:28:51 PM
How can I code my merge document so that when the merge executes, at a
certain point in the last paragraph, a message box appears on screen to
remind the user to do something?

Blah blah blah [MsgBox: Don't forget to mail the voucher when the merge is
done!] Blah blah blah.

TIA,
Kathy


Re: MsgBox during merge
"Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> 5/10/2007 8:01:40 AM
If you mean that the box would pop up around the point when the very last
paragraph for the very last record is merged, the simplest way is to use VBA
to initiate the merge, e.g.

Sub MergeAndMsgbox()

With ActiveDocument.MailMerge
' set the destination you want
.Destination = wdSendToNewDocument
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
MsgBox "your message"

End Sub

Otherwise, I think you can only do this if you have information that tells
you what the last record to be merged is. For example, if your merge data
has a field called lastrecord and it is only set to "Y" in the last record)
then you could do something like the following:

{ IF { MERGEFIELD lastrecord } = "Y" "{ ASK junk "whatever message you want
to display" }" "" }

If you don't have an item that does that, then it's more difficult since
Word doesn't have a field that returns the number of records being merged.
Since IMO it would only be worth doing this for reasonably long merges you
might be able to pick an arbitrary record number that's always going to be
smaller than the actual record count and pop up your box at that point in
the merge, e.g.

{ IF { MERGESEQ } = 10000 "{ ASK junk "whatever message you want to
display" }" "" }

WIth some data sources you could probably discover the record count using a
{ DATABASE } field.

As far as your other post concerning formatting within INCLUDETEXTed
documents is concerned, we went through all the possibilities I can think of
last month (did you mange to try using the character format that macropod
suggested?) - I won't respond to your post in case someone else has a better
idea, but if you want to send me the mail merge main document, included
documents etc. I will have a look at them - despam my e-mail address by
taking out the KillmapS and send them.

Peter Jamieson

"Kathy Webster" <slickdock[ at ]yahoo.com> wrote in message
news:46425934$0$18913$4c368faf[ at ]roadrunner.com...
[Quoted Text]
> How can I code my merge document so that when the merge executes, at a
> certain point in the last paragraph, a message box appears on screen to
> remind the user to do something?
>
> Blah blah blah [MsgBox: Don't forget to mail the voucher when the merge is
> done!] Blah blah blah.
>
> TIA,
> Kathy
>

Re: MsgBox during merge
"Kathy Webster" <slickdock[ at ]yahoo.com> 5/10/2007 11:03:51 PM
Peter,

I am currently using {ASK}. I wanted a cleaner prompt, one like the message
box gives.

Since I have one master macro to initiate all merges, and only certain merge
forms that need this prompt, I need to identify on a form by form basis
which one gives the MsgBox. Is there a way to put code somewhere in the
merge form itself, telling the form to run a VBA procedure or macro at that
point in the merge process? (Identifying the last record in the merge is
not a problem for me...I'm good with that part)

Regarding the INCLUDETEXT debacle, see my reply to my new fiance, Bear ;-)

Kathy

"Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> wrote in message
news:273C66F6-A667-49E4-AF5D-C909BD59528D[ at ]microsoft.com...
[Quoted Text]
> If you mean that the box would pop up around the point when the very last
> paragraph for the very last record is merged, the simplest way is to use
> VBA to initiate the merge, e.g.
>
> Sub MergeAndMsgbox()
>
> With ActiveDocument.MailMerge
> ' set the destination you want
> .Destination = wdSendToNewDocument
> With .DataSource
> .FirstRecord = wdDefaultFirstRecord
> .LastRecord = wdDefaultLastRecord
> End With
> .Execute Pause:=False
> End With
> MsgBox "your message"
>
> End Sub
>
> Otherwise, I think you can only do this if you have information that tells
> you what the last record to be merged is. For example, if your merge data
> has a field called lastrecord and it is only set to "Y" in the last
> record) then you could do something like the following:
>
> { IF { MERGEFIELD lastrecord } = "Y" "{ ASK junk "whatever message you
> want to display" }" "" }
>
> If you don't have an item that does that, then it's more difficult since
> Word doesn't have a field that returns the number of records being merged.
> Since IMO it would only be worth doing this for reasonably long merges you
> might be able to pick an arbitrary record number that's always going to be
> smaller than the actual record count and pop up your box at that point in
> the merge, e.g.
>
> { IF { MERGESEQ } = 10000 "{ ASK junk "whatever message you want to
> display" }" "" }
>
> WIth some data sources you could probably discover the record count using
> a { DATABASE } field.
>
> As far as your other post concerning formatting within INCLUDETEXTed
> documents is concerned, we went through all the possibilities I can think
> of last month (did you mange to try using the character format that
> macropod suggested?) - I won't respond to your post in case someone else
> has a better idea, but if you want to send me the mail merge main
> document, included documents etc. I will have a look at them - despam my
> e-mail address by taking out the KillmapS and send them.
>
> Peter Jamieson
>
> "Kathy Webster" <slickdock[ at ]yahoo.com> wrote in message
> news:46425934$0$18913$4c368faf[ at ]roadrunner.com...
>> How can I code my merge document so that when the merge executes, at a
>> certain point in the last paragraph, a message box appears on screen to
>> remind the user to do something?
>>
>> Blah blah blah [MsgBox: Don't forget to mail the voucher when the merge
>> is done!] Blah blah blah.
>>
>> TIA,
>> Kathy
>>
>


Re: MsgBox during merge
"Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> 5/10/2007 11:37:57 PM
[Quoted Text]
> Is there a way to put code somewhere in the merge form itself

There are several ways to start a merge. What is your understanding of a
"Merge form" ?

> (Identifying the last record in the merge is not a problem for me...I'm
> good with that part)
>

How are you proposing to do it?

> Regarding the INCLUDETEXT debacle, see my reply to my new fiance, Bear ;-)

FWIW, this ground was covered in the previous thread, but "You pays your
money and You takes your choice" :-)

Peter Jamieson


"Kathy Webster" <slickdock[ at ]yahoo.com> wrote in message
news:4643a4dd$0$2432$4c368faf[ at ]roadrunner.com...
> Peter,
>
> I am currently using {ASK}. I wanted a cleaner prompt, one like the
> message box gives.
>
> Since I have one master macro to initiate all merges, and only certain
> merge forms that need this prompt, I need to identify on a form by form
> basis which one gives the MsgBox. Is there a way to put code somewhere in
> the merge form itself, telling the form to run a VBA procedure or macro at
> that point in the merge process? (Identifying the last record in the
> merge is not a problem for me...I'm good with that part)
>
> Regarding the INCLUDETEXT debacle, see my reply to my new fiance, Bear ;-)
>
> Kathy
>
> "Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> wrote in message
> news:273C66F6-A667-49E4-AF5D-C909BD59528D[ at ]microsoft.com...
>> If you mean that the box would pop up around the point when the very last
>> paragraph for the very last record is merged, the simplest way is to use
>> VBA to initiate the merge, e.g.
>>
>> Sub MergeAndMsgbox()
>>
>> With ActiveDocument.MailMerge
>> ' set the destination you want
>> .Destination = wdSendToNewDocument
>> With .DataSource
>> .FirstRecord = wdDefaultFirstRecord
>> .LastRecord = wdDefaultLastRecord
>> End With
>> .Execute Pause:=False
>> End With
>> MsgBox "your message"
>>
>> End Sub
>>
>> Otherwise, I think you can only do this if you have information that
>> tells you what the last record to be merged is. For example, if your
>> merge data has a field called lastrecord and it is only set to "Y" in the
>> last record) then you could do something like the following:
>>
>> { IF { MERGEFIELD lastrecord } = "Y" "{ ASK junk "whatever message you
>> want to display" }" "" }
>>
>> If you don't have an item that does that, then it's more difficult since
>> Word doesn't have a field that returns the number of records being
>> merged. Since IMO it would only be worth doing this for reasonably long
>> merges you might be able to pick an arbitrary record number that's always
>> going to be smaller than the actual record count and pop up your box at
>> that point in the merge, e.g.
>>
>> { IF { MERGESEQ } = 10000 "{ ASK junk "whatever message you want to
>> display" }" "" }
>>
>> WIth some data sources you could probably discover the record count using
>> a { DATABASE } field.
>>
>> As far as your other post concerning formatting within INCLUDETEXTed
>> documents is concerned, we went through all the possibilities I can think
>> of last month (did you mange to try using the character format that
>> macropod suggested?) - I won't respond to your post in case someone else
>> has a better idea, but if you want to send me the mail merge main
>> document, included documents etc. I will have a look at them - despam my
>> e-mail address by taking out the KillmapS and send them.
>>
>> Peter Jamieson
>>
>> "Kathy Webster" <slickdock[ at ]yahoo.com> wrote in message
>> news:46425934$0$18913$4c368faf[ at ]roadrunner.com...
>>> How can I code my merge document so that when the merge executes, at a
>>> certain point in the last paragraph, a message box appears on screen to
>>> remind the user to do something?
>>>
>>> Blah blah blah [MsgBox: Don't forget to mail the voucher when the merge
>>> is done!] Blah blah blah.
>>>
>>> TIA,
>>> Kathy
>>>
>>
>
>

Re: MsgBox during merge
"Kathy Webster" <slickdock[ at ]yahoo.com> 5/11/2007 1:20:02 AM
[Quoted Text]
>> Is there a way to put code somewhere in the merge form itself
>
> There are several ways to start a merge. What is your understanding of a
> "Merge form" ?

I don't have a problem starting the merge. I have a problem interceding once
the merge has started. A Merge Form, in my definition, is started through
Tools, letters and mailings, creating the main document and the datasource.
I am refering to the Main Document when I refer to "Mergeform." It has
{MERGEFIELD} codes in it, as well as Word field codes, such as{FILLIN},
{ASK}, etc.

I want the merge to start and process up to a certain point, then stick in a
Message along the way. I can start the merge with VBA, no problem. I'm
having trouble interceding midway through the mergeform with a message box.


Re: MsgBox during merge
"Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> 5/11/2007 1:49:34 AM
[Quoted Text]
> I want the merge to start and process up to a certain point, then stick in
> a Message along the way. I can start the merge with VBA, no problem. I'm
> having trouble interceding midway through the mergeform with a message
> box.

OK, in that case the VBA that does . Execute then Msgbox that I suggested
clearly isn't going to work.

> Identifying the last record in the merge is not a problem for me...I'm
> good with that part)

What options are available to you on this front, before the merge is
initiated? Can you use VBA to determine how many records are about to be
merged - e.g. if the source is Access or Excel, you might be able to issue a
SQL query via ADo to detrmine the record count? Or maybe you could iterate
through MailMerge.DataSource in VBA once without actually merging, just to
establish how many records there are?

Peter Jamieson
"Kathy Webster" <slickdock[ at ]yahoo.com> wrote in message
news:4643c4d8$0$8932$4c368faf[ at ]roadrunner.com...
>>> Is there a way to put code somewhere in the merge form itself
>>
>> There are several ways to start a merge. What is your understanding of a
>> "Merge form" ?
>
> I don't have a problem starting the merge. I have a problem interceding
> once the merge has started. A Merge Form, in my definition, is started
> through Tools, letters and mailings, creating the main document and the
> datasource. I am refering to the Main Document when I refer to
> "Mergeform." It has {MERGEFIELD} codes in it, as well as Word field codes,
> such as{FILLIN}, {ASK}, etc.
>
> I want the merge to start and process up to a certain point, then stick in
> a Message along the way. I can start the merge with VBA, no problem. I'm
> having trouble interceding midway through the mergeform with a message
> box.
>
>

Re: MsgBox during merge
"Kathy Webster" <slickdock[ at ]yahoo.com> 5/18/2007 1:59:34 AM
I don't understand. I don't need to know how many records there are. I have
that covered. I need to know how to execute a message box when the merge is
complete.

"Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> wrote in message
news:1B0A4A4A-2FB2-4F37-9D77-0B243CAABC9E[ at ]microsoft.com...
[Quoted Text]
>> I want the merge to start and process up to a certain point, then stick
>> in a Message along the way. I can start the merge with VBA, no problem.
>> I'm having trouble interceding midway through the mergeform with a
>> message box.
>
> OK, in that case the VBA that does . Execute then Msgbox that I suggested
> clearly isn't going to work.
>
>> Identifying the last record in the merge is not a problem for me...I'm
>> good with that part)
>
> What options are available to you on this front, before the merge is
> initiated? Can you use VBA to determine how many records are about to be
> merged - e.g. if the source is Access or Excel, you might be able to issue
> a SQL query via ADo to detrmine the record count? Or maybe you could
> iterate through MailMerge.DataSource in VBA once without actually merging,
> just to establish how many records there are?
>
> Peter Jamieson
> "Kathy Webster" <slickdock[ at ]yahoo.com> wrote in message
> news:4643c4d8$0$8932$4c368faf[ at ]roadrunner.com...
>>>> Is there a way to put code somewhere in the merge form itself
>>>
>>> There are several ways to start a merge. What is your understanding of a
>>> "Merge form" ?
>>
>> I don't have a problem starting the merge. I have a problem interceding
>> once the merge has started. A Merge Form, in my definition, is started
>> through Tools, letters and mailings, creating the main document and the
>> datasource. I am refering to the Main Document when I refer to
>> "Mergeform." It has {MERGEFIELD} codes in it, as well as Word field
>> codes, such as{FILLIN}, {ASK}, etc.
>>
>> I want the merge to start and process up to a certain point, then stick
>> in a Message along the way. I can start the merge with VBA, no problem.
>> I'm having trouble interceding midway through the mergeform with a
>> message box.
>>
>>
>


Re: MsgBox during merge
"Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> 5/18/2007 6:47:56 AM
[Quoted Text]
> I need to know how to execute a message box when the merge is complete.

It seems to me that if you can start the merge with VBA and you only need
the message when the merge is complete, then you can use the method I
suggested earlier where you pop up a MsgBox after the .Execute

The only reason I suggested that that might not work after all was because
it seemed you were suggesting that you wanted the message to pop up
mid-merge, in which case you would have to know the record count.

But if all you want to do is be able to put something in your Mail Merge
Main Document (or let your users put that something in) that will let your
VBA decide whether or not to pop up that MsgBox, then you could put in
almost anything that is unambiguous, easily detected in VBA, does not result
in any output. It could be a bookmark with a certain name, for example.

If you want users to be able to specify at the beginning of the merge
whether they want a message box at the end, you could for example insert an
ASK field that uses the \o switch (so it only asks once at the beginning of
the merge) and sets a bookmark with a special name that you specify, e.g.
"tellmewhenitsallover" or some such.

Then in your VBA, after the .Exceute, you could
a. check for the existence of that tellmewhenitsallover bookmark in the
MailMerge
b. if it isn't there, don't prompt
c. if it is there, check its value. If it's y or Y prompt. Otherwise, don't
prompt.

For that you would need something like the following (change the bookmark
name etc. to suit).

Sub MergeAndOptionalMsgbox()
Dim objMMMD As Word.Document

Set objMMMD = ActiveDocument
With objMMMD.MailMerge
' set the destination you want
.Destination = wdSendToNewDocument
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
On Error Goto bookmarknotfound
If ucase(trim(objMMMD.Bookmarks("tellmewhenitsover").Range.Text)) = "Y" Then
MsgBox "Pause!"
End If
bookmarknotfound:
Err.Clear
On Error Goto 0

End Sub

If you need to make it easy for the user to insert such an Ask, you could
consider using an AutoText or another bit of VBA code to insert it.

Peter Jamieson

"Kathy Webster" <slickdock[ at ]yahoo.com> wrote in message
news:464d0884$0$12450$4c368faf[ at ]roadrunner.com...
>I don't understand. I don't need to know how many records there are. I have
>that covered. I need to know how to execute a message box when the merge is
>complete.
>
> "Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> wrote in message
> news:1B0A4A4A-2FB2-4F37-9D77-0B243CAABC9E[ at ]microsoft.com...
>>> I want the merge to start and process up to a certain point, then stick
>>> in a Message along the way. I can start the merge with VBA, no problem.
>>> I'm having trouble interceding midway through the mergeform with a
>>> message box.
>>
>> OK, in that case the VBA that does . Execute then Msgbox that I suggested
>> clearly isn't going to work.
>>
>>> Identifying the last record in the merge is not a problem for me...I'm
>>> good with that part)
>>
>> What options are available to you on this front, before the merge is
>> initiated? Can you use VBA to determine how many records are about to be
>> merged - e.g. if the source is Access or Excel, you might be able to
>> issue a SQL query via ADo to detrmine the record count? Or maybe you
>> could iterate through MailMerge.DataSource in VBA once without actually
>> merging, just to establish how many records there are?
>>
>> Peter Jamieson
>> "Kathy Webster" <slickdock[ at ]yahoo.com> wrote in message
>> news:4643c4d8$0$8932$4c368faf[ at ]roadrunner.com...
>>>>> Is there a way to put code somewhere in the merge form itself
>>>>
>>>> There are several ways to start a merge. What is your understanding of
>>>> a "Merge form" ?
>>>
>>> I don't have a problem starting the merge. I have a problem interceding
>>> once the merge has started. A Merge Form, in my definition, is started
>>> through Tools, letters and mailings, creating the main document and the
>>> datasource. I am refering to the Main Document when I refer to
>>> "Mergeform." It has {MERGEFIELD} codes in it, as well as Word field
>>> codes, such as{FILLIN}, {ASK}, etc.
>>>
>>> I want the merge to start and process up to a certain point, then stick
>>> in a Message along the way. I can start the merge with VBA, no problem.
>>> I'm having trouble interceding midway through the mergeform with a
>>> message box.
>>>
>>>
>>
>
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net