ObjWord As Word.Application

Shop Girl

Registered User.
Local time
Today, 14:55
Joined
Sep 2, 2002
Messages
18
I have lifted out of the Access Developers Handbook the code for opening a Word document and entering data from the db into it.

However it falls down on this first line!!!!!

Dim ObjWord As Word.Application

I get a compile error:

User-defined type not defined

with the words ObjWord As Word.Application in red.

Any ideas as to why this is not working?
 
I use the following.

Dim objWord As Object
Set objWord = CreateObject("Word.Application")
 
Many thanks - that got over that hurdle...

Now I can't fathom out how to put the document path in... The example in the book isn't exactly helpful.

Here is what is written at present:

objWord.Documents.Add _
Application.CurrentProject.Path & "\FactPackLetter.dot"

I've left it the same path for the moment as I don't know understand it. The document name is correct.

I need to point the code to MyDocuments and the template is in there. Can you help me this?

Thanks again
 
objWord.Documents.Add _
Application.CurrentProject.Path & "\FactPackLetter.dot"

The Application.CurrentProject.Path is the path that the Db is actually in. You can specify an alternative path eg

objWord.Documents.Add _
"C:\MyDocuments\FactPackLetter.dot"

You may get some more useful snippets of code and good tips if you search the forum here for 'mail merge'
 
Thank you - I've been having a look round the other posts and I'd just got there with the path thing but I've now got this problem...

It says that my template does not exist! It flipping well does - I can see it! I even copied the name from the Word file to make sure I wasn't spelling it incorrectly.

Have you ever wanted to take a big stick and...:mad:

If you have got any ideas as to why this might be happening I'd really would be grateful.

Thanks for your help
 
OK I sussed that one - I don't know what the problem was but I retyped the first part of the code and it now works up to the next point where you supply it with information to be used in the documents bookmarks.

And then it falls over saying that the "object is required"

The bookmarks are in the document and my form is just called Customers. the method the code is using is eg

.Item("CompanyName").Range.Text = Customers.CompanyName

Is this right? Or is there some other way to do this (preferably one that works)

:confused:
 
I Gave up with that one

After plodding on through the night - I couldn't get that code to work at all. So I gave up and now am using code from another post on this forum. Which works great I'm pleased to say. I am now considering using my Developer's handbook as a doorstop!!

I still have a little problem. How do I tell this piece of code that if there is nothing in the field, carry on and move to the next field? It currently stops and gives me the error - invalid use of null.

.ActiveDocument.bookmarks("Address2").Select
.selection.Text = (CStr(Forms!Customers!Address2))

And if I do it - will I have a blank line in my Word document?

Thanks for your patience - I only dabble in code when I can't get access to do it the easy way!
 
You could think about replacing your new doorstop with a copy of the Access Cookbook, published by O'Reilly. It has lots of useful information. Some fairly basic and alot more complex.
 
if not isnull((CStr(Forms!Customers!Address2))) then
.ActiveDocument.bookmarks("Address2").Select
.selection.Text = (CStr(Forms!Customers!Address2))
end if

If you use a mailmerge, word will automatically suppress blanks.
 

Users who are viewing this thread

Back
Top Bottom