Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Look2TheSky2 Look2TheSky2 is offline
external usenet poster
 
Posts: 11
Default Mail Merge Recipent List - Result Value

In my project, I must include a field in my document stating the number of
records found resulting from my mail merge recipient query.
How do I determine this value, and include it as a field in my merge document?

Thanks in advance for your consideration and assistance.

Jennifer
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Mail Merge Recipent List - Result Value

Unfortunately there is no field that returns this value.

In the general case you can't even use a SQL query (e.g. in a DATABASE
field) to return the count, because in addition to any query that Word
generates, the user can select/deselect individual records.

You can however, get the count using VBA, e.g.

Function MyRecordCount() As Long
Dim lngRecordCount as Long
Dim lngFirstRecord As Long
Dim lngLastRecord As Long
Dim lngRecord As Long
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord ' the last
selected record
lngLastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
' Get the first record, selected or not.
' If there are no selected records, this fails
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstDataSourceRecord
lngFirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
lngRecordCount = 0
For lngRecord = lngFirstRecord To lngLastRecord
If ActiveDocument.MailMerge.DataSource.Included Then
lngRecordCount = lngRecordCount + 1
End If
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextDataSourceRecord
Next
MyRecordCount = lngRecordCount
End Function

You can then insert that in your document or use it (for example) to set a
Document Variable called RecordCount
that you can insert using a { DOCVARIABLE RecordCount } field.

Peter Jamieson

"Look2TheSky2" wrote in message
...
In my project, I must include a field in my document stating the number of
records found resulting from my mail merge recipient query.
How do I determine this value, and include it as a field in my merge
document?

Thanks in advance for your consideration and assistance.

Jennifer


  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Look2TheSky2 Look2TheSky2 is offline
external usenet poster
 
Posts: 11
Default Mail Merge Recipent List - Result Value

Thank you so much Peter for your reply.
I regret that outside of simple macro editing, my knowledge of VBA is sadly
deficient.
Once I know how to use this code, where to put it, how to define a variable,
I can give it a whirl. (I did open up VB editor and cut and paste your code
following a "Dim RecordCount As String" line into a module, but doubt that
was correct.

Thank you again for your support.

Jen

"Peter Jamieson" wrote:

Unfortunately there is no field that returns this value.

In the general case you can't even use a SQL query (e.g. in a DATABASE
field) to return the count, because in addition to any query that Word
generates, the user can select/deselect individual records.

You can however, get the count using VBA, e.g.

Function MyRecordCount() As Long
Dim lngRecordCount as Long
Dim lngFirstRecord As Long
Dim lngLastRecord As Long
Dim lngRecord As Long
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord ' the last
selected record
lngLastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
' Get the first record, selected or not.
' If there are no selected records, this fails
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstDataSourceRecord
lngFirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
lngRecordCount = 0
For lngRecord = lngFirstRecord To lngLastRecord
If ActiveDocument.MailMerge.DataSource.Included Then
lngRecordCount = lngRecordCount + 1
End If
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextDataSourceRecord
Next
MyRecordCount = lngRecordCount
End Function

You can then insert that in your document or use it (for example) to set a
Document Variable called RecordCount
that you can insert using a { DOCVARIABLE RecordCount } field.

Peter Jamieson

"Look2TheSky2" wrote in message
...
In my project, I must include a field in my document stating the number of
records found resulting from my mail merge recipient query.
How do I determine this value, and include it as a field in my merge
document?

Thanks in advance for your consideration and assistance.

Jennifer



  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Mail Merge Recipent List - Result Value

How to use it depends partly on when you need to insert the result.

For installing and running macros, see Graham Mayor's page at

http://www.gmayor.com/installing_macro.htm

However, you will need a bit more info. to insert the result of the macro.
One way to do it would be to insert a macrobutton (see another of Graham's
pages at

http://www.gmayor.com/Macrobutton.htm

You would need one like

{ MACROBUTTON InsertMailMergeRecordCount [Click here to insert the mailmerge
record count] }

(Use ctrl-F9 to insert the { })

Then add the following to your existing VBA module:

Public Sub InsertMailMergeRecordCount()
Selection.TypeText cstr(MyRecordCount())
End Sub

Peter Jamieson


"Look2TheSky2" wrote in message
...
Thank you so much Peter for your reply.
I regret that outside of simple macro editing, my knowledge of VBA is
sadly
deficient.
Once I know how to use this code, where to put it, how to define a
variable,
I can give it a whirl. (I did open up VB editor and cut and paste your
code
following a "Dim RecordCount As String" line into a module, but doubt
that
was correct.

Thank you again for your support.

Jen

"Peter Jamieson" wrote:

Unfortunately there is no field that returns this value.

In the general case you can't even use a SQL query (e.g. in a DATABASE
field) to return the count, because in addition to any query that Word
generates, the user can select/deselect individual records.

You can however, get the count using VBA, e.g.

Function MyRecordCount() As Long
Dim lngRecordCount as Long
Dim lngFirstRecord As Long
Dim lngLastRecord As Long
Dim lngRecord As Long
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord ' the
last
selected record
lngLastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
' Get the first record, selected or not.
' If there are no selected records, this fails
ActiveDocument.MailMerge.DataSource.ActiveRecord =
wdFirstDataSourceRecord
lngFirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
lngRecordCount = 0
For lngRecord = lngFirstRecord To lngLastRecord
If ActiveDocument.MailMerge.DataSource.Included Then
lngRecordCount = lngRecordCount + 1
End If
ActiveDocument.MailMerge.DataSource.ActiveRecord =
wdNextDataSourceRecord
Next
MyRecordCount = lngRecordCount
End Function

You can then insert that in your document or use it (for example) to set
a
Document Variable called RecordCount
that you can insert using a { DOCVARIABLE RecordCount } field.

Peter Jamieson

"Look2TheSky2" wrote in message
...
In my project, I must include a field in my document stating the number
of
records found resulting from my mail merge recipient query.
How do I determine this value, and include it as a field in my merge
document?

Thanks in advance for your consideration and assistance.

Jennifer




  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Look2TheSky2 Look2TheSky2 is offline
external usenet poster
 
Posts: 11
Default Mail Merge Recipent List - Result Value

Thanks so much for your help.
I've got some reading to do. If I fail to get the results I seek, at least
you have pointed me to a great reference.

Jen

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I get the mail merge result as a hyperlink? Alwin Morgenstern Mailmerge 2 August 17th 06 06:50 PM
How do I print a recipient list from a mail merge list in Word? Randog Mailmerge 1 June 20th 06 06:52 PM
Printing select number of labels from a mail merge result Judy Mailmerge 1 May 31st 05 08:50 PM
Printing a list of recipients from a mail merge list Kathryn at GJS Microsoft Word Help 1 March 9th 05 04:34 PM
Emailed Merge Recipent 'Cannot find datasource' Cory Blythe Mailmerge 4 January 17th 05 02:37 PM


All times are GMT +1. The time now is 12:40 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"