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 / Mailmerge and Fax / January 2006

Tip: Looking for answers? Try searching our database.

Office 2003 SP2

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bdogsputnik - 12 Jan 2006 23:35 GMT
My code was working fine and recently stopped. Has there been a
security update that's changed things?

Basically my script writes a text file, then opens a word document that
points to it for it's data.

The error I'm getting is: "Compile error: Method or data member not
found"

CODE BELOW:

Function MergeIt(DocName As String, PrintIt As String, QueryName As
String)
'Merges a Query (QueryName) with a Word document (the DocName) in
T:\Program Files\GSCB
On Error GoTo MergeItErr
   Dim Query2Export As String
   Dim File2Create As String
   Dim DocLocation As String
   Dim WordObj As Object
   Dim actWindow As String
   Dim MyPath
   Dim FoundLabel As Integer
   Dim DocNameChange As String
   Dim vbResponse
   Dim Copies As Integer

       MyPath = "T:\Program Files\GSCB"
       ChDrive "T"
       ChDir "T:\Program Files\GSCB"

       If DocName = "Generic Fair Letter" Then
           Copies = InputBox("How many copies?")

       ElseIf DocName = "Generic Vendor Letter" Then
           Copies = InputBox("How many copies?")

       End If

       'DoCmd.Echo False
       'DoCmd.Hourglass True

'Export Speficications
'Set Values
On Error Resume Next
       Kill "*.INI"
       Kill "*.TXT"
On Error GoTo MergeItErr
       Query2Export = QueryName
       File2Create = MyPath & "\" & DocName & ".txt"
       DoCmd.TransferText acExportMerge, , Query2Export, File2Create,
True

'Launch MsWord

'You can find all these new commands in Word by opening a blank
document,
'pressing Alt + F11, then F2 and searching the words there or looking
'them up in the help file

         Set WordObj = CreateObject("Word.Application") 'This is now
the Word object
         DocLocation = MyPath & "\" & DocName & ".doc"
         Dim oDoc As Document
       Set oDoc = WordObj.Documents.Open(FileName:=DocLocation)

       'Merge the documents
           With oDoc.MailMerge <<<<<<<<<<------------This is the Line
that causes the error
               .OpenDataSource Name:= _
       File2Create, ConfirmConversions:= _
       False, ReadOnly:=False, LinkToSource:=True,
AddToRecentFiles:=False, _
       PasswordDocument:="", PasswordTemplate:="",
WritePasswordDocument:="", _
       WritePasswordTemplate:="", Revert:=False,
Format:=wdOpenFormatAuto, _
       Connection:="", SQLStatement:="", SQLStatement1:="", SubType:=
_
       wdMergeSubTypeOther
               .Destination = wdSendToNewDocument
               .SuppressBlankLines = True
           'With .DataSource
               '.FirstRecord = wdDefaultFirstRecord
               '.LastRecord = wdDefaultLastRecord
           'End With
           .Execute Pause:=False
           End With

<<<<.............other code removed .............>>>>>>>>>
End Function

Any help? Thanks!
Cindy M  -WordMVP- - 17 Jan 2006 14:33 GMT
Hi Bdogsputnik,

> My code was working fine and recently stopped. Has there been a
> security update that's changed things?
[quoted text clipped - 5 lines]
> found"
>  
I don't currently have an installation with Office 2003 SP2, so I can't
test this for you, but...

You use late-binding for the Word application: dim objWord as Object
Then early-binding for the document: Dim oDoc as document

This could be causing some problems if you've lost the reference to the
Word object library. If you do this, does it help:
   Dim oDoc as Object

> CODE BELOW:
>  
[quoted text clipped - 78 lines]
> <<<<.............other code removed .............>>>>>>>>>
> End Function

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
bdogsputnik - 23 Jan 2006 19:27 GMT
For those who find this article later.

The answer was that:

Dim oDoc as Document

should be changed to:

Dim oDoc as Word.Document

Happy Coding!

Brian
Envision Consulting
Business Technology Solutions for Small Businesses
http://www.envisionyourvision.com
 
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.