Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Micah Micah is offline
external usenet poster
 
Posts: 3
Default VB for mailmerge that worked in 97

I changed computers and upgraded from Office 97 to Office 2003. The
following lines worked in a Excel 97 document and will not run in 2003. Any
suggestions would be appreciated.

With AppFile
'Changes the Current Directory.
.ChangeFileOpenDirectory "G:\Capital Projects\Invoice Cover
Sheets\"
'Opens the desired file from Current Directory.
.Documents.Open Filename:="""PPR Template.doc""",
ConfirmConversions:=False, ReadOnly:=False, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="",
Format:=wdOpenFormatAuto
'Runs MailMerge to fill in CONSTRUCTION DATA.
ActiveDocument.MailMerge.OpenDataSource Name:= _
"G:\Capital Projects\Invoice Cover Sheets\Current
Projects\Construction\Payment Management.xls" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";Us er ID=Admin;Data
Source=G:\Capital Projects\Invoice Cover Sheets\Current
Projects\Engineering\Payment Management ENG.xls;Mode=Read;Extended
Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:" _
, SQLStatement:="SELECT * FROM `'Monthly Payment$'` WHERE `Payment
Due` 0", SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
'Shows the Data rather than Fields.
.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
'Merge the Data to the printer.
.ActiveDocument.MailMerge.Destination = wdSendToPrinter
.ActiveDocument.MailMerge.SuppressBlankLines = True
.ActiveDocument.MailMerge.DataSource.FirstRecord =
wdDefaultFirstRecord
.ActiveDocument.MailMerge.DataSource.LastRecord =
wdDefaultLastRecord
.ActiveDocument.MailMerge.Execute Pause:=False
End With

The error occurs with the following statement
WHERE `Payment Due` 0",
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default VB for mailmerge that worked in 97

Unfortunately, the OpenDataSource code that Word generates when you record
your macros does not always work. In this case I can see the following
potentiqaol problems...

The pathname you have in the Name parameter of OpenDataSource:

G:\Capital Projects\Invoice Cover Sheets\Current
Projects\Construction\Payment Management.xls

is different from the one you have in the Connection string:

G:\Capital Projects\Invoice Cover Sheets\Current
Projects\Engineering\Payment Management ENG.xls

The Connection String is incomplete (not obvious). But in this case I do not
think you need it anyway.

What I suggest you try is

ActiveDocument.MailMerge.OpenDataSource _
Name:="G:\Capital Projects\Invoice Cover Sheets\Current
Projects\Construction\Payment Management.xls", _
SQLStatement:="SELECT * FROM [Monthly Payment$] WHERE [Payment due] 0"

You obviously need to use the correct pathname in the Name parameter. I tend
to use [ ] rather than ` ` to surround names in the SQL starement simply
because it makes things clearer. If that does not work, try using a table
alias, e.g.

ActiveDocument.MailMerge.OpenDataSource _
Name:="G:\Capital Projects\Invoice Cover Sheets\Current
Projects\Construction\Payment Management.xls", _
SQLStatement:="SELECT * FROM [Monthly Payment$] MP WHERE MP.[Payment due]
0"

although tests here suggest you do not need one.

--
Peter Jamieson
http://tips.pjmsn.me.uk

"Micah" wrote in message
...
I changed computers and upgraded from Office 97 to Office 2003. The
following lines worked in a Excel 97 document and will not run in 2003.
Any
suggestions would be appreciated.

With AppFile
'Changes the Current Directory.
.ChangeFileOpenDirectory "G:\Capital Projects\Invoice Cover
Sheets\"
'Opens the desired file from Current Directory.
.Documents.Open Filename:="""PPR Template.doc""",
ConfirmConversions:=False, ReadOnly:=False, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="",
Format:=wdOpenFormatAuto
'Runs MailMerge to fill in CONSTRUCTION DATA.
ActiveDocument.MailMerge.OpenDataSource Name:= _
"G:\Capital Projects\Invoice Cover Sheets\Current
Projects\Construction\Payment Management.xls" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";Us er ID=Admin;Data
Source=G:\Capital Projects\Invoice Cover Sheets\Current
Projects\Engineering\Payment Management ENG.xls;Mode=Read;Extended
Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:"
_
, SQLStatement:="SELECT * FROM `'Monthly Payment$'` WHERE `Payment
Due` 0", SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
'Shows the Data rather than Fields.
.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
'Merge the Data to the printer.
.ActiveDocument.MailMerge.Destination = wdSendToPrinter
.ActiveDocument.MailMerge.SuppressBlankLines = True
.ActiveDocument.MailMerge.DataSource.FirstRecord =
wdDefaultFirstRecord
.ActiveDocument.MailMerge.DataSource.LastRecord =
wdDefaultLastRecord
.ActiveDocument.MailMerge.Execute Pause:=False
End With

The error occurs with the following statement
WHERE `Payment Due` 0",


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
can't locate the last few worked on documents Jacqui Smith Microsoft Word Help 1 June 11th 08 09:41 AM
It worked JudithJubilee Microsoft Word Help 0 January 5th 07 01:15 PM
How do I transfer data to disk to be worked on somewhere else lawrence Microsoft Word Help 1 November 15th 06 06:19 AM
How to fix outlining feature, it has never worked RCJones Microsoft Word Help 1 April 23rd 05 05:00 PM
I worked on a document on my other PC. but now I 'm trying to mod. Farouk New Users 1 December 29th 04 10:07 PM


All times are GMT +1. The time now is 03:32 PM.

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"