By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,591 Members | 629 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,591 IT Pros & Developers. It's quick & easy.

Word function out of Access 97 non-responsive after Access 2003 Upgrade

P: n/a
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"
'Insert the variables' contents into the bookmarks in Word
With objWord
.EditBookmark Name:="txtCompany", GoTo:=True
.INSERT Company
.EditBookmark Name:="txtWorkPhone", GoTo:=True
.INSERT WorkPhone
.EditBookmark Name:="txtFirstName", GoTo:=True
.INSERT FirstName
.EditBookmark Name:="txtLastName", GoTo:=True
.INSERT LastName
.EditBookmark Name:="txtAddress", GoTo:=True
.INSERT Address
.EditBookmark Name:="txtPostalCode", GoTo:=True
.INSERT PostalCode
.EditBookmark Name:="txtCity", GoTo:=True
.INSERT City
.EditBookmark Name:="txtSalutation", GoTo:=True
.INSERT Salutation
.EditBookmark Name:="txtState", GoTo:=True
.INSERT State
.EditBookmark Name:="txtSignature", GoTo:=True
.INSERT Signature
.EditBookmark Name:="txtClosing", GoTo:=True
.INSERT Closing
End With
Any help would be greatly appreciated.

Thanks

-Ryan


*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
What issues are you having? Did you change versions of Word when you
upgraded Access? How is objWord declared?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Ryan Muller" <ry*********@mikronvinyl.com> wrote in message
news:H5******************@news.uswest.net...
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"
'Insert the variables' contents into the bookmarks in Word
With objWord
.EditBookmark Name:="txtCompany", GoTo:=True
.INSERT Company
.EditBookmark Name:="txtWorkPhone", GoTo:=True
.INSERT WorkPhone
.EditBookmark Name:="txtFirstName", GoTo:=True
.INSERT FirstName
.EditBookmark Name:="txtLastName", GoTo:=True
.INSERT LastName
.EditBookmark Name:="txtAddress", GoTo:=True
.INSERT Address
.EditBookmark Name:="txtPostalCode", GoTo:=True
.INSERT PostalCode
.EditBookmark Name:="txtCity", GoTo:=True
.INSERT City
.EditBookmark Name:="txtSalutation", GoTo:=True
.INSERT Salutation
.EditBookmark Name:="txtState", GoTo:=True
.INSERT State
.EditBookmark Name:="txtSignature", GoTo:=True
.INSERT Signature
.EditBookmark Name:="txtClosing", GoTo:=True
.INSERT Closing
End With
Any help would be greatly appreciated.

Thanks

-Ryan


*** Sent via Developersdex http://www.developersdex.com ***

Nov 13 '05 #2

P: n/a
We upgraded completely to Office 2003, so Word, Powerpoint, Access, and
Excel have all been upgraded from 97 to 2003.

Basically the issues we are having are:

1. Word won't open as it did when running the code in 97.
2. When you open a session of Word and go to the Window tab you can
select a document that has some of the information but is missing the
majority of the letter.

Here is how objWord is declared and the rest of the code:

Option Compare Database
Option Explicit
'Shared public variables
Dim objWord As Object
Const StrTemplPath = "r:\r&d\masters\address\"

Public Function AdrInfo()
Dim frmCurrForm As Form
Dim Company, FirstName, LastName, Salutation, State As String
Dim Address, City, PostalCode, WorkPhone, Closing, Signature As
String
' Dim StrTemplPath As String
Set frmCurrForm = Screen.ActiveForm

'Change the template path to match where you placed the sample
template
'StrTemplPath = "q:\mike\"
'StrTemplPath = "c:\temp\"
' strRef = InputBox("Type the reference line")

'Pass the information from the current record to the variables
With frmCurrForm
Company = .Company
FirstName = .FirstName
LastName = .LastName
WorkPhone = .WorkPhone
Address = .Address
City = .City
PostalCode = .PostalCode
Salutation = .FirstName
State = .State
Signature = .txtFrom
Closing = .txtClosing
End With

'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"
'Insert the variables' contents into the bookmarks in Word
With objWord
.EditBookmark Name:="txtCompany", GoTo:=True
.INSERT Company
.EditBookmark Name:="txtWorkPhone", GoTo:=True
.INSERT WorkPhone
.EditBookmark Name:="txtFirstName", GoTo:=True
.INSERT FirstName
.EditBookmark Name:="txtLastName", GoTo:=True
.INSERT LastName
.EditBookmark Name:="txtAddress", GoTo:=True
.INSERT Address
.EditBookmark Name:="txtPostalCode", GoTo:=True
.INSERT PostalCode
.EditBookmark Name:="txtCity", GoTo:=True
.INSERT City
.EditBookmark Name:="txtSalutation", GoTo:=True
.INSERT Salutation
.EditBookmark Name:="txtState", GoTo:=True
.INSERT State
.EditBookmark Name:="txtSignature", GoTo:=True
.INSERT Signature
.EditBookmark Name:="txtClosing", GoTo:=True
.INSERT Closing
End With

'Pass the Request ID to the calling code
End Function

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #3

P: n/a
Ryan Muller <ry*********@mikronvinyl.com> wrote in
news:H5******************@news.uswest.net:
Set objWord = CreateObject("Word.Basic")


Don't you want this:

Set objWord = CreateObject("Word.Application")

instead?

I don't know what Word.Basic refers to, but I do know that
Word.Basic was the macro language for Word before Word95, when it
was replaced with VBA.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #4

P: n/a
I can get word to open and have updated the code to reflect Visual Basic
(I suspected it was in Word Basic and that wasn't supported in Office
2003). However, I cannot get the bookmarks to work. The code that we
were using to insert the Access field information into the Word Document
bookmark is in the above post.

Here is the code I used to get Word to open:

'Start Word and create a new doc from the template
Set objWord = CreateObject("Word.Application")
objWord.Application.Visible = True
'objWord.AppMaximize "Microsoft Word", 1
objWord.Documents.Add Template:="r:\r&d\masters\address\letter.dot"

Here is what I have tried to get the bookmarks to transfer
(unsuccessfully):

With objWord
'Grabs the Bookmark name in the open Word template
.Bookmarks("txtCompany").Select
'Selects the field in the current form to insert into the
bookmark
.Selection.TypeText Company

End With

Any help would be appreciated.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #5

P: n/a
Got it to work, thanks for your help.

The key was adding the ActiveDocument property to the beginning on the
Bookmarks statement.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #6

P: n/a
Ryan Muller wrote:
We upgraded completely to Office 2003, so Word, Powerpoint, Access, and
Excel have all been upgraded from 97 to 2003.

Basically the issues we are having are:

1. Word won't open as it did when running the code in 97.
2. When you open a session of Word and go to the Window tab you can
select a document that has some of the information but is missing the
majority of the letter.

Here is how objWord is declared and the rest of the code:

Option Compare Database
Option Explicit
'Shared public variables
Dim objWord As Object
Const StrTemplPath = "r:\r&d\masters\address\"

Public Function AdrInfo()
Dim frmCurrForm As Form
Dim Company, FirstName, LastName, Salutation, State As String
Dim Address, City, PostalCode, WorkPhone, Closing, Signature As
String
' Dim StrTemplPath As String
Set frmCurrForm = Screen.ActiveForm

'Change the template path to match where you placed the sample
template
'StrTemplPath = "q:\mike\"
'StrTemplPath = "c:\temp\"
' strRef = InputBox("Type the reference line")

'Pass the information from the current record to the variables
With frmCurrForm
Company = .Company
FirstName = .FirstName
LastName = .LastName
WorkPhone = .WorkPhone
Address = .Address
City = .City
PostalCode = .PostalCode
Salutation = .FirstName
State = .State
Signature = .txtFrom
Closing = .txtClosing
End With

'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"
'Insert the variables' contents into the bookmarks in Word
With objWord
.EditBookmark Name:="txtCompany", GoTo:=True
.INSERT Company
.EditBookmark Name:="txtWorkPhone", GoTo:=True
.INSERT WorkPhone
.EditBookmark Name:="txtFirstName", GoTo:=True
.INSERT FirstName
.EditBookmark Name:="txtLastName", GoTo:=True
.INSERT LastName
.EditBookmark Name:="txtAddress", GoTo:=True
.INSERT Address
.EditBookmark Name:="txtPostalCode", GoTo:=True
.INSERT PostalCode
.EditBookmark Name:="txtCity", GoTo:=True
.INSERT City
.EditBookmark Name:="txtSalutation", GoTo:=True
.INSERT Salutation
.EditBookmark Name:="txtState", GoTo:=True
.INSERT State
.EditBookmark Name:="txtSignature", GoTo:=True
.INSERT Signature
.EditBookmark Name:="txtClosing", GoTo:=True
.INSERT Closing
End With

'Pass the Request ID to the calling code
End Function

*** Sent via Developersdex http://www.developersdex.com ***


The Word.Basic object doesn't exist... it's now a collection off the
Application object, i.e., Word.Application.WordBasic.

Try this instead

1. make a reference to the Word object library in the Access VBA IDE
(Tools->References, Microsoft Word X.0 Object Library).

2. try this code instead:

dim objWord as Word.Application
dim objWordDoc as Word.Document

set objWord = new Word.Application
objWord.visible = true

set objWordDoc = objWord.documents.add("path to template.dot")

'now, you have to insert the data you want into the bookmarks, which you
'do by getting the "Range" object for the bookmark:

objWordDoc.Bookmarks("txtSalutation").Range.Insert After me.Salutation

'or, more efficiently...
with objWordDoc
.bookmarks("txtSalutation").range.insertAfter me.salutation
.bookmarks("txtClosing").range.insertAfter me.txtclosing
...
end with

'...then save the document
objWordDoc.SaveAs("filename")

'finally...
objWordDoc.Close(wdDoNotSaveChanges) 'wdDoNotSaveChanges = 0
set objWordDoc = nothing

'close Word...
objWord.Quit(wdDoNotSaveChanges) 'wdDoNotSaveChanges = 0
set objWord = nothing

---------------------

The Me reference is a shortcut to Screen.ActiveForm, even in non-form
modules.

Add error trapping...

I usually do it like this:

public sub MySubRoutine
on error goto errs

....

errs:
select case err.number
case 0:
'no errors. just fall through
'case 3265, etc. - handle specific errors
case else:
debug.print err.number, err.description
end select

'close out any objects, transactions, etc. here...
end sub

YMMV. I wish I could "shortcut" it, but I'm so used to typing it...
Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.