Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How can I get the mail merge result as a hyperlink? | Mailmerge | |||
How do I print a recipient list from a mail merge list in Word? | Mailmerge | |||
Printing select number of labels from a mail merge result | Mailmerge | |||
Printing a list of recipients from a mail merge list | Microsoft Word Help | |||
Emailed Merge Recipent 'Cannot find datasource' | Mailmerge |