Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2006

Tip: Looking for answers? Try searching our database.

Mailmerge Value in to a variable

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gaz uk - 07 Feb 2006 15:52 GMT
Hi

I'm having trouble getting the value of a mailmerge field in to a variable.  
I think I may be approaching this the wrong way but as a test I put the
following code into a template and instead of the actual value for CCode I
get   <<ClientCode>>

Private Sub Document_New()
   For Each mmField In ActiveDocument.Fields
           If mmField.Code = " MERGEFIELD ClientCode " Then
              CCode = mmField.Result
              x = MsgBox("Client Code is " & CCode, vbOKOnly)
           End If
   Next mmField
End Sub

Is it that the value isn't coming in because the data hasn't merged yet?

I'm sure there is probably a straight forward answer but have dug around and
found nothing that works.

Thanks in advance

Gaz
Doug Robbins - Word MVP - 07 Feb 2006 19:16 GMT
Probably better if you tell us what you want to do with the variable.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi
>
[quoted text clipped - 22 lines]
>
> Gaz
Gaz uk - 07 Feb 2006 22:00 GMT
The word template is opened by a third party app that somehow pushes through
the mailmerge fields to create the document.  I want to take some of the
values and check them, which if incorrect will close the document and not
allow it to be created.  In other words I'm forcing the user to fill out the
info in the 3rd party app otherwise it won't let them create the document.

Hope this explains ok

Gaz

> Probably better if you tell us what you want to do with the variable.
>
[quoted text clipped - 24 lines]
> >
> > Gaz
Doug Robbins - Word MVP - 08 Feb 2006 05:04 GMT
You may (small letters) be able to do what you want with mailmerge events.
For an exampe of their use, take a look at the add-in that you can download
from

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

You are probably better off to work directly with the data source however
before the merge, rather than try and do it via the mail merge main
document.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> The word template is opened by a third party app that somehow pushes
> through
[quoted text clipped - 39 lines]
>> >
>> > Gaz
Peter Jamieson - 08 Feb 2006 10:29 GMT
The result depends on the state of

   ActiveDocument.MailMerge.ViewMailMergeFieldCodes

You can also consider getting the current value of the mailmerge field using
e.g.

ActiveDocument.MailMerge.DataSource.DataFields("ClientCode")

Peter Jamieson

> Hi
>
[quoted text clipped - 22 lines]
>
> Gaz
Gaz uk - 08 Feb 2006 10:46 GMT
Tried both of these and got an error for both, (Runtime error 5852.  
Requested object is not available)

Any other thoughts appreciated

Thanks

Gaz

> The result depends on the state of
>
[quoted text clipped - 33 lines]
> >
> > Gaz
Peter Jamieson - 08 Feb 2006 12:43 GMT
That suggests that at the point you are running the code, the Word document
is not connected to the data source (and is not strictly speaking a mail
merge main document).

I suspect that to get any worthwhile results you will have to connect to the
datasource first. Because the merge is being done by a third party
application, it's difficult to know how you might achieve that. Have you
been able to work out how the app. is providing data to the Mailmerge
"application" ? Is it creating a temporary text file, or what?

Peter Jamieson
> Tried both of these and got an error for both, (Runtime error 5852.
> Requested object is not available)
[quoted text clipped - 46 lines]
>> >
>> > Gaz
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.