473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Dim objDoc As Word.Document isn't working!

I have been searching everywhere to try to figure out how to use Access to open an existing Word document that is merged to an Excel spreadsheet and merge the data when it opens. I'm working with two different version, Word 2000 and 2003. I got it to work perfect in 2000, but when I use it in 2003, the Word document opens and it is not linked to a data source.

The closest thing I have found to help me out is a function written on this site called MergeIt(), but when I compile, this line, "Dim objDoc As Word.Document," gives me this error: Compile error: User-defined type not defined.

What am I doing wrong? Any help is GREATLY appreciated. I have already spent way too much time on trying to figure this one out.

Here is the code I'm trying to use:

Function MergeIt()

On Error GoTo ErrHandling

Dim objDoc As Word.Document
Dim objWord As Word.Application
Dim blnCreated As Boolean
Dim strFilename As String
Dim strQueryName As String
Dim strDBpath As String

strFilename = "e:\SUMMONSFORM.DOC"
strQueryName = "qryOWNERCODEFENDANTsummonsmergedata"
strDBpath = "E:\CityTaxSaleV63.mdb" 'Or probably just CurrentDb.Name

On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err Then
Set objWord = CreateObject("Word.Application")
blnCreated = True
End If

On Error GoTo ErrHandling

Set objDoc = objWord.Documents.Open(strFilename)

'Make Word Visible
objWord.Visible = True

'Execute the MailMerge
With objDoc.MailMerge
'Set Merge Data Source
objDoc.MailMerge.OpenDataSource Name:=strDBpath, _
LinktoSource:=True, _
Connection:="QUERY " & strQueryName, _
SQLStatement:="SELECT * FROM " & strQueryName
.Destination = wdSendToNewDocument
.Execute
objWord.ActiveDocument.PrintOut False
objWord.ActiveDocument.Close wdDoNotSaveChanges
End With

'Close The form files and the merged document
objDoc.Close wdDoNotSaveChanges

If blnCreated Then
objWord.Quit
End If

Set objDoc = Nothing
Set objWord = Nothing

Exit Function

ErrHandling:
msgbox "Whoops" 'Better error handling of course
End Function


Thanks!
Jody
Apr 2 '07 #1
3 27162
Denburt
1,356 Expert 1GB
In your VBA window go to tools then references and add a reference to Microsoft Word.
Apr 2 '07 #2
Thanks for your fast help! That did it.
Apr 3 '07 #3
Denburt
1,356 Expert 1GB
Glad I could help. :)
Apr 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: ingvald | last post by:
hi, i've hit a wall regarding php and ms word. what i want is to open a document containing bookmarks, insert text where the bookmarks are, and save. it's working, unless the bookmark is in...
4
by: Tom Dauria | last post by:
What I am trying to do is write a resume into a word document from information in an Access database. I have been using bookmarks and inserting table results into the document and so far it's...
3
by: di | last post by:
I have a Access Database, and I would like to create a word document that (preferable would filter)links to ACCESS table or query. I would like to print the word document on the filtered record...
7
by: Zeke | last post by:
I'm using the following code to create word document but the problem is if you go to task manager you'll see a WINWORD.EXE process is running but not the application, here is the code: ...
1
by: ourspt | last post by:
Hi, We are working on an ASP.NET (VB.NET) application and we have a problem opening a word document from our application. When we try to open the word document, we do not get any error...
0
southoz
by: southoz | last post by:
Good ay all , I'm fairly new to access(a little over 5 weeks now). Since I'v started I have picked up a lot of useful information from forums such as this and in doing so will share that information...
5
by: TriciaL | last post by:
Hi all, I've been going through the threads on the Mergit() function to run a Word mailmerge out of Access, and I've hit a roadblock. The first problem I had was discussed in this thread:...
2
by: saketmayur | last post by:
Hi , I have write the following code to open word document on server using Microsoft.Office.Interop.Word; string DocPath = System.Configuration.ConfigurationManager.AppSettings; ...
5
by: bullfrog83 | last post by:
I'm opening a merged word document from Access using VBA and I'm having two problems. When the user clicks the Merge Template button code executes that sets a query for the data merging and at the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.