PDA

View Full Version : Events not firing



mitchell50
10-29-2007, 04:53 PM
I have written some VBA code in Word 2003. It takes advantage of the MailMergeBeforeRecordMerge event. It seems to work fine on Word 2003 but when someone tries use it in a Word 2000 environment, the event doesn't fire.

I don't have any events in the Normal.dot document. In the merge document I set a public object to an instance of the application as follows:

Public WithEvents Wrd As WORD.Application

Private Sub Document_Open()
Set Wrd = ThisDocument.Application
End Sub

The Document_Open() sub fires just fine in W2000. It even seems to set the instance. But the following event doesn't fire:

Private Sub Wrd_MailMergeBeforeRecordMerge(ByVal Doc As Document, Cancel As Boolean)

For Each Item In Doc.MailMerge.DataSource.DataFields
MsgBox "Field Name: " & Item.Name & " Value: " & Item.Value
Next

End Sub

I do remember one time I had to set up a public object in Normal.dot that was set to a class (with events) whenever Normal was initiated. Is this what I should do? I hate the idea of having to alter the Normal.dot on every computer that is going to use this document.

OTWarrior
10-30-2007, 02:07 AM
you shouldn't need to set anything in the normal.dot, however try changing
Set Wrd = ThisDocument.Application

to

Set Wrd = activedocument.Application

also, what have you set doc as in your line.

For Each Item In Doc.MailMerge.DataSource.DataFields


my best guess would be a function you are using from 2003 is not avaible in 2000

try putting an error handle in (if you haven't done so already) with err.description.

eg:
on error goto Error

'your code here

error:
msgbox err.description


Hope that helps

mitchell50
10-30-2007, 09:09 AM
Thanks. I'll give this a try and report.

The Doc object is set to the object passed by the system in the MailMergeBeforeRecordMerge event (Doc as Document).

mitchell50
10-30-2007, 02:36 PM
It looks like Word 2000 only supports about 10 events. Mail merge isn't one of them.

I need to do some calculations based on some of the merge fields. If I try to process anything before the merge starts, none of the fields are available. If I go into a DoEvents loop, the merge never begins. Does anyone have any idea how to get to these merge fields in Word 2000?

TonyJollans
10-31-2007, 02:55 AM
Basically, you can't do it in Word 2000 - time for an upgrade.

You will either have to work with the data source before the merge, or the complete merge document afterwards.

mitchell50
10-31-2007, 09:35 AM
Thanks for the comment. Unfortunately, I can't make the client upgrade because the solution probably isn't worth the $3,000 it would cost. I'll have to do some really screwy work-around.

OTWarrior
10-31-2007, 09:56 AM
are you able to use the mail merge items in the end document (such as a bookmark or index number) to call the value and use it for calculations?

ie:
your mail merge changes the text in [[data1]].
mail merge proceedure is finished.
(activedocument.formfields("data1"))*2 = (activedocument.formfields("endData1"))

nb: i have never used mail merge so this is a shot in the dark, but i hope it helps.

TonyJollans
10-31-2007, 10:42 AM
I don't know what calculations you want to do so I can't really advise much. You might be able to use formula fields and just update them after the merge.