473,395 Members | 1,466 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,395 software developers and data experts.

Use Access to pass values to Word document

I am new in this area. I want to use values in a Access database and pass
them to a word document. I tried this test code in a form of the Access
database but it didn't work (temp.doc is a word doc already stored in C:
drive):

Dim oX As Object
Set oX = CreateObject("C:\temp.doc")
oX.editreplace "<<FirstName>>", "Richard", 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0
oX.Application.Visible = True
Set oX = Nothing
End Sub
It returns an error message something like "The object doesn't support this
property" (it stops at 3rd line in the above code). I know I must have
missed something, but don't know what it is. Any help is appreciate it.

Richard

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200612/1

Dec 2 '06 #1
5 6487

ruomingxu via AccessMonster.com wrote:
I am new in this area. I want to use values in a Access database and pass
them to a word document. I tried this test code in a form of the Access
database but it didn't work (temp.doc is a word doc already stored in C:
drive):

Dim oX As Object
Set oX = CreateObject("C:\temp.doc")
oX.editreplace "<<FirstName>>", "Richard", 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0
oX.Application.Visible = True
Set oX = Nothing
End Sub
It returns an error message something like "The object doesn't support this
property" (it stops at 3rd line in the above code). I know I must have
missed something, but don't know what it is. Any help is appreciate it.

Richard

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200612/1
Richard,
you could probably use Albert Kallal's MergeToWord function to do this.
http://www.members.shaw.ca/AlbertKal...rge/index.html

He makes it about as easy as falling off a log.

Dec 2 '06 #2

You could use so-called Automation. Microsoft's help file tells you
more or less everything you need to know. Here's the Office 2000 one
http://support.microsoft.com/kb/260410 but there are others for
different versions. I started using this technique in Access 97. I'm
now on 2003 and it still works perfectly without the need to make any
changes.

The basic idea is to store the documents as templates, and those
templates contain named bookmarks. The VBA code opens the template as a
new document and inserts the required data at the relevant bookmarks.

It works perfectly for me and is pretty easy to get your head round

Dave

Dec 3 '06 #3
Dave,

Thanks for your tips. I will check them out.

Richard
Dave G @ K2 wrote:
>You could use so-called Automation. Microsoft's help file tells you
more or less everything you need to know. Here's the Office 2000 one
http://support.microsoft.com/kb/260410 but there are others for
different versions. I started using this technique in Access 97. I'm
now on 2003 and it still works perfectly without the need to make any
changes.

The basic idea is to store the documents as templates, and those
templates contain named bookmarks. The VBA code opens the template as a
new document and inserts the required data at the relevant bookmarks.

It works perfectly for me and is pretty easy to get your head round

Dave
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200612/1

Dec 6 '06 #4
Dave,

I am using Office 2002. I created a test doc at "C:\My Documents\Wordtest.
doc" and basically copied and pasted the code from the web you recommented
into a Access test database:

---------
Sub FindBMark()

Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Dim wordRange As Word.Range

Set wordApp = CreateObject("Word.Application")
Set wordDoc = wordApp.Documents.Open("C:\My Documents\Wordtest.doc")

wordApp.Visible = True

' go to the bookmark named "City."
Set wordRange = wordDoc.Goto(What:=wdGoToBookmark, Name:="City")
wordRange.InsertAfter "Los Angeles"

' print the document.
wordDoc.PrintOut Background:=False

' save the modified document.
wordDoc.Save

' quit Word without saving changes to the document.
wordApp.Quit SaveChanges:=wdDoNotSaveChanges

Set wordApp = Nothing

End Sub
--------------

But it didn't work. I don't know if it is related to Office version. There
are maily 2 types of errors when I run the above code:

1. It doesn't recognized this declaration:
Dim wordApp As Word.Application

2. In some of the lines, it error message is "Object doesn't support this
property or method"

Any help will be appreciated.

Richard

Dave G @ K2 wrote:
>You could use so-called Automation. Microsoft's help file tells you
more or less everything you need to know. Here's the Office 2000 one
http://support.microsoft.com/kb/260410 but there are others for
different versions. I started using this technique in Access 97. I'm
now on 2003 and it still works perfectly without the need to make any
changes.

The basic idea is to store the documents as templates, and those
templates contain named bookmarks. The VBA code opens the template as a
new document and inserts the required data at the relevant bookmarks.

It works perfectly for me and is pretty easy to get your head round

Dave
--
Message posted via http://www.accessmonster.com

Dec 6 '06 #5
Try this; it creates the document as an Object:

Dim mWord As Object
Set mWord = CreateObject("Word.Application")
mWord.Documents.Add "C:\My Documents\Wordtest.doc"
With mWord.ActiveDocument
.Bookmarks("City").Range.Fields(1).Result.Text = "Los Angeles"
End With
mWord.Visible = True
Set mWord = Nothing

--
Darryl Kerkeslager
1. It doesn't recognized this declaration:
Dim wordApp As Word.Application

2. In some of the lines, it error message is "Object doesn't support this
property or method"

Any help will be appreciated.

Richard


Dec 7 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ronny Sigo | last post by:
Hello all, I am a newbie to access. I try to pass data from a form into a new Word document Below you see how far I got ... can anybody help ? Private Sub btnMaakbrief_Click() If lGoon =...
5
by: Fly Girl | last post by:
Gurus needed! I'm trying to use a Word class object in order to capture events in Word. Here's what I have, but the event code appWord_BeforeDocumentSave... doesn't ever fire. In a Class Module...
9
by: Tony Williams | last post by:
I have an Access database that we use as a document index system. The documents can be Word, Excel, pdf's etc I have a command button on a form that opens the document in whatever program is...
9
by: Neil Ginsberg | last post by:
I have a strange situation using Access to automate a Word mail merge. Using Access 2000 and Word 2000, the code opens Word, opens the document in Word, sets a table in the calling Access...
6
by: Ryan Muller | last post by:
My company just upgraded from Access 97 to Access 2003 today and we are having some issues in a database that generates a Word document from information selected in a form. Here is the code we...
2
by: amith.srinivas | last post by:
Hi all, From a word macro in VBA, I am trying to create a report in access DB. The report is based on a query with a parameter. I am using Set rpt = Application.CreateReport rpt.RecordSource =...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
7
by: JDOMPer | last post by:
Don’t misunderstand me – I use AJAX, but I think there is a far simpler, elegant alternative that just uses Javascript, the DOM and Php ( hence - JDOMP) for data transfers, and is cross-browser...
10
by: mlevit | last post by:
Hi, I've found a tutorial that shows you how to fill in Word documents with values from Access 'Print customer slip for current customer. Dim appWord As Word.Application Dim doc As...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.