Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
Hi newsgroup,
I'm quite familiar how Word is handling SELECT-statements. What I want to do is to programmatically access/set the state of the checkboxes in the "mailmerge recipients list" in order to set that state on my own Word form (which includes a similar recipients list). How is Word reaching that unchecked items are not printed when executing the mail merge? Could someone bring more light on this, please? Your time and help is higly appreciated. Kind regards, Steffen |
#2
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
Roughly speaking the checked/unchecked states of these boxes correspond to
the value of ActiveDocument.MailMerge.DataSource.Included for the ActiveRecord. In other words, if you want to set or examine the checkbox value, you have to navigate to the record you want then examine or modify the value of ..Included. However, a. it isn't particularly easy to manipulate the .ActiveRecord reliably, in the general case (the facilities for doing this are a bit weird, and if you do it one way, you'll find that when you iterate through the records, you will not even see the ones where Included is set to False) b. my recent tests in this area have tended to hang Word. -- Peter Jamieson http://tips.pjmsn.me.uk "Steffen Grellmann" wrote in message ... Hi newsgroup, I'm quite familiar how Word is handling SELECT-statements. What I want to do is to programmatically access/set the state of the checkboxes in the "mailmerge recipients list" in order to set that state on my own Word form (which includes a similar recipients list). How is Word reaching that unchecked items are not printed when executing the mail merge? Could someone bring more light on this, please? Your time and help is higly appreciated. Kind regards, Steffen |
#3
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
Hi Peter,
thank you for replying. On Wed, 12 Dec 2007 09:18:49 -0000, "Peter Jamieson" wrote: Roughly speaking the checked/unchecked states of these boxes correspond to the value of ActiveDocument.MailMerge.DataSource.Included for the ActiveRecord. This was exactly what I wanted to know for getting started on this matter. Thank you! I just want to give you a short response before I'm getting deeper into it. In other words, if you want to set or examine the checkbox value, you have to navigate to the record you want then examine or modify the value of .Included. OK, I have checked this but it's not working that simple as it is described in the F1 help. However, a. it isn't particularly easy to manipulate the .ActiveRecord reliably, in the general case (the facilities for doing this are a bit weird, and if you do it one way, you'll find that when you iterate through the records, you will not even see the ones where Included is set to False) It seems tricky and buggy. I will do some more testing and give you an response. b. my recent tests in this area have tended to hang Word. ACK! Kind regards, Steffen |
#4
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
You probably need something like the following:
--------------------------------------------- Sub x() Dim lLastRecord As Long With ActiveDocument.MailMerge.DataSource .ActiveRecord = wdLastDataSourceRecord lLastRecord = .ActiveRecord .ActiveRecord = wdFirstDataSourceRecord Debug.Print CStr(.ActiveRecord) & ": " & CStr(.Included) Do Until .ActiveRecord = lLastRecord .ActiveRecord = wdNextDataSourceRecord Debug.Print CStr(.ActiveRecord) & ": " & CStr(.Included) Loop End With End Sub --------------------------------------------- But I can't remember which version of Word first had wdLastDataSourceRecord etc. You also need to consider the possibility that with some data sources, Word may not actually be able to determine the number of the last record without reading the entire data source, e.g. if the data source is an OLE DB source with a "forward only cursor". Ther may also be problems in a multi-user environment if someone adds or deletes records while you iterate through them (I really do not know what Word does in that case)/ Although you can /set/ .ActiveRecord to the special values like wdLastDataSourceRecord , you can't compare .ActiveRecord to them because in that case VBA thinks you are trying to compare .ActiveRecord with a negative integer. Personally, I think this confusion of actual numeric values and symbolic values is a very poor way to do things. -- Peter Jamieson http://tips.pjmsn.me.uk "Steffen Grellmann" wrote in message ... Hi Peter, thank you for replying. On Wed, 12 Dec 2007 09:18:49 -0000, "Peter Jamieson" wrote: Roughly speaking the checked/unchecked states of these boxes correspond to the value of ActiveDocument.MailMerge.DataSource.Included for the ActiveRecord. This was exactly what I wanted to know for getting started on this matter. Thank you! I just want to give you a short response before I'm getting deeper into it. In other words, if you want to set or examine the checkbox value, you have to navigate to the record you want then examine or modify the value of .Included. OK, I have checked this but it's not working that simple as it is described in the F1 help. However, a. it isn't particularly easy to manipulate the .ActiveRecord reliably, in the general case (the facilities for doing this are a bit weird, and if you do it one way, you'll find that when you iterate through the records, you will not even see the ones where Included is set to False) It seems tricky and buggy. I will do some more testing and give you an response. b. my recent tests in this area have tended to hang Word. ACK! Kind regards, Steffen |
#5
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
Hi Peter,
thank you for replying. My main problem at that point is that I can't read the value of ..Included without an error message in that case, that a new connection to the data source has been freshly established /and/ Word's recipients list has not been opened by clicking the appropriate button on the command bar at minimum once! Any suggestions? I don't want to solve this by opening the recipients list per code (Dialogs(wdDialogMailMergeRecipients).Show). Setting the SetAllErrorFlags and SetAllIncludedFlags even do not solve this behaviour. Sub x() Dim lLastRecord As Long With ActiveDocument.MailMerge.DataSource .ActiveRecord = wdLastDataSourceRecord lLastRecord = .ActiveRecord .ActiveRecord = wdFirstDataSourceRecord Debug.Print CStr(.ActiveRecord) & ": " & CStr(.Included) Do Until .ActiveRecord = lLastRecord .ActiveRecord = wdNextDataSourceRecord Debug.Print CStr(.ActiveRecord) & ": " & CStr(.Included) Loop End With End Sub Thanks for that snippet. This is quite helpful because .RecordCount always returns -1 when "SELECT DISTINCT..." is used (which I have to use for some special reasons...). And .LastRecord is returning a negative value in some cases! But I can't remember which version of Word first had wdLastDataSourceRecord etc. Word 97 definetly don't have the wdLastDataSourceRecord, relying on some articles, Word 2000 and newer has (not tested). Ther may also be problems in a multi-user environment if someone adds or deletes records while you iterate through them (I really do not know what Word does in that case)/ I will do some tests on this as soon as it is clear that my plan to use the Checkstate on my own form can be realized. Although you can /set/ .ActiveRecord to the special values like wdLastDataSourceRecord , you can't compare .ActiveRecord to them because in that case VBA thinks you are trying to compare .ActiveRecord with a negative integer. But this doesn't matter if I would use your snippet above which is using the value of .LastRecord instead of .RecordCount, which I would normally use in For...Next constructs, or I'm wrong? Personally, I think this confusion of actual numeric values and symbolic values is a very poor way to do things. ACK! Kind regards, Steffen |
#6
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
Hi Steffen,
I knew there was a reason why I never manipulated .Included but I had forgotten what it was. I get exactly the same thing here. I can't think of a way around it - even performing a merge to a new document does not magically create the .included objects. You can trap the error when you test .Included. I suppose that is enough to tell you that all the records must be included (because the user has not looked at the Recipients dialog box) but I can't see how you can get Word to create these objects without showing the dialog. I will see if I can find out anything more about this. -- Peter Jamieson http://tips.pjmsn.me.uk "Steffen Grellmann" wrote in message ... Hi Peter, thank you for replying. My main problem at that point is that I can't read the value of .Included without an error message in that case, that a new connection to the data source has been freshly established /and/ Word's recipients list has not been opened by clicking the appropriate button on the command bar at minimum once! Any suggestions? I don't want to solve this by opening the recipients list per code (Dialogs(wdDialogMailMergeRecipients).Show). Setting the SetAllErrorFlags and SetAllIncludedFlags even do not solve this behaviour. Sub x() Dim lLastRecord As Long With ActiveDocument.MailMerge.DataSource .ActiveRecord = wdLastDataSourceRecord lLastRecord = .ActiveRecord .ActiveRecord = wdFirstDataSourceRecord Debug.Print CStr(.ActiveRecord) & ": " & CStr(.Included) Do Until .ActiveRecord = lLastRecord .ActiveRecord = wdNextDataSourceRecord Debug.Print CStr(.ActiveRecord) & ": " & CStr(.Included) Loop End With End Sub Thanks for that snippet. This is quite helpful because .RecordCount always returns -1 when "SELECT DISTINCT..." is used (which I have to use for some special reasons...). And .LastRecord is returning a negative value in some cases! But I can't remember which version of Word first had wdLastDataSourceRecord etc. Word 97 definetly don't have the wdLastDataSourceRecord, relying on some articles, Word 2000 and newer has (not tested). Ther may also be problems in a multi-user environment if someone adds or deletes records while you iterate through them (I really do not know what Word does in that case)/ I will do some tests on this as soon as it is clear that my plan to use the Checkstate on my own form can be realized. Although you can /set/ .ActiveRecord to the special values like wdLastDataSourceRecord , you can't compare .ActiveRecord to them because in that case VBA thinks you are trying to compare .ActiveRecord with a negative integer. But this doesn't matter if I would use your snippet above which is using the value of .LastRecord instead of .RecordCount, which I would normally use in For...Next constructs, or I'm wrong? Personally, I think this confusion of actual numeric values and symbolic values is a very poor way to do things. ACK! Kind regards, Steffen |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
mailmerge recipients | Mailmerge | |||
How do I make a list of people from an *.mdb recipients list | Mailmerge | |||
can't add to recipients list | Mailmerge | |||
Printing a list of recipients from a mail merge list | Microsoft Word Help | |||
Mailmerge Recipients doesn't work with SQL Server | Mailmerge |