473,698 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.c om
http://www.accessmonster.com/Uwe/For...ccess/200612/1

Dec 2 '06 #1
5 6510

ruomingxu via AccessMonster.c om 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.c om
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.c om
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\Wordt est.
doc" and basically copied and pasted the code from the web you recommented
into a Access test database:

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

Dim wordApp As Word.Applicatio n
Dim wordDoc As Word.Document
Dim wordRange As Word.Range

Set wordApp = CreateObject("W ord.Application ")
Set wordDoc = wordApp.Documen ts.Open("C:\My Documents\Wordt est.doc")

wordApp.Visible = True

' go to the bookmark named "City."
Set wordRange = wordDoc.Goto(Wh at:=wdGoToBookm ark, Name:="City")
wordRange.Inser tAfter "Los Angeles"

' print the document.
wordDoc.PrintOu t Background:=Fal se

' save the modified document.
wordDoc.Save

' quit Word without saving changes to the document.
wordApp.Quit SaveChanges:=wd DoNotSaveChange s

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.Applicatio n

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("W ord.Application ")
mWord.Documents .Add "C:\My Documents\Wordt est.doc"
With mWord.ActiveDoc ument
.Bookmarks("Cit y").Range.Field s(1).Result.Tex t = "Los Angeles"
End With
mWord.Visible = True
Set mWord = Nothing

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

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
2981
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 = False Then ' Here I check some of the controls to see if they contain required data, if not a msgbox is displayed
5
2690
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 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Public WithEvents appWord As Word.Application Public WithEvents docWord As Word.Document Public Sub appWord_DocumentBeforeSave(ByVal Doc As Word.Document,
9
2327
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 relevant. The code I use is Private Sub Cmdstart_Click() On Error GoTo Err_Handler Dim strPath As String If IsNull(DocURLtxt.Value) Then strmsg = "You must enter the Document URL to use this function
9
4322
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 application as the data source, and then performs a merge. Everything works fine. However, when a user uses it in Access 2002 and Word 2002, an extra instance of the Access application is opened and remains open at the end. Sometimes it remains open
6
2678
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 were using without issue previous to the switch: 'Start Word and create a new doc from the template Set objWord = CreateObject("Word.Basic") objWord.AppMaximize "Microsoft Word", 1 objWord.FileNew Template:=StrTemplPath & "letter.dot"
2
9344
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 = <<Query_Name>> Once I create the report, I m trying to create labels to display the Report title in the Report Header section.
4
12437
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 this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
7
2023
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 without the need for work arounds. JDOMP works in recent versions of Explorer, Mozilla, Safari and Opera. Please note I will not deal with security issues which are always an issue whenever there is access to a database. You can simply change text on...
10
9241
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 Word.Document 'Avoid error 429, when Word isn't open. On Error Resume Next Err.Clear
0
8598
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9152
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9014
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7708
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.