Filling Word Form from Access

F

fmackay

Hi,

I am trying to fill fields on a Word form from an Access db - I found
this page: http://msdn2.microsoft.com/en-us/library/aa140082(office.
10).aspx
and used this code - successfully. But I have now moved onto a machine
with slightly newer versions of Access and VB, and now get error 91 -
object variable or with block variable not set at the line
Set doc = .Documents.Open(DOC_PATH & DOC_NAME, , True)

The machine where the code worked has Access 2002 SP2 and VB 6.3.8863,
the one I'm using now where the code breaks has Access 2002 SP3 and VB
6.4.8869; they probably have slightly different versions of Word, too,
but both Word 10.

The relevant code is:

Const DOC_PATH As String = "<path>"
Const DOC_NAME As String = "<filename>"

Dim appWord As Word.Application
Dim doc As Word.Document
Dim rst As ADODB.Recordset

On Error Resume Next

Set appWord = GetObject(, "Word.application")

If Err = 429 Then
Set appWord = New Word.Application
Err = 0
End If

With appWord

On Error GoTo ErrorHandler

Set doc = .Documents.Open(DOC_PATH & DOC_NAME, , True)

Set rst = New ADODB.Recordset


Any ideas?

Many thanks,

Finlay Mackay
 
P

Perry

Go into VBE and check menu: Tools | References
whether there are libraries reported "MISSING" in the references.
Write them down somewhere ... (or make a screendump)
Uncheck these missing references, validate the dialog and retry.

If this doesn't work, bring up the very same reference dialog, and from the
note that you made (or the screendump), look for a more recent version.

Kindly repost if this doesn't work.

Krgrds,
Perry
 
F

fmackay

Go into VBE and check menu: Tools | References
whether there are libraries reported "MISSING" in the references.
Write them down somewhere ... (or make a screendump)
Uncheck these missing references, validate the dialog and retry.

If this doesn't work, bring up the very same reference dialog, and from the
note that you made (or the screendump), look for a more recent version.

Kindly repost if this doesn't work.

Hi,

There are no missing libraries, and the same ones are checked on both
machines. Although I suppose I can't assume the libs are identical
despite them having the same names; I can see 6 different libs all
calling themselves "Visual Basic for Applications" after all (it
appears I am using the same one of these on both machines though)

cheers,

Finlay
 
P

Perry

Ok, let's bring in some phasing and see what problems

If you were to skip using the active instance of Word (the GetObject
instantiating) and use
a brand new instance of Word

Replace this
Set appWord = GetObject(, "Word.application")
If Err = 429 Then
Set appWord = New Word.Application
Err = 0
End If
With appWord
On Error GoTo ErrorHandler
Set doc = .Documents.Open(DOC_PATH & DOC_NAME, , True)

by
Set appWord = New Word.Application
With appWord
On Error GoTo ErrorHandler
Set doc = .Documents.Open(DOC_PATH & DOC_NAME, , True)
'...etc
End With

Is wdApp instantiated and can you get object variable "doc" instantiated as
well ...?
 
F

fmackay

Ok, let's bring in some phasing and see what problems

If you were to skip using the active instance of Word (the GetObject
instantiating) and use
a brand new instance of Word

Replace this


by
Set appWord = New Word.Application
With appWord
On Error GoTo ErrorHandler
Set doc = .Documents.Open(DOC_PATH & DOC_NAME, , True)
'...etc
End With

I tried this already, "Set appWord = New Word.Application" does start
a new WINWORD.EXE process but I can't seem to do anything with it, eg
if I follow that line with "appWord.Visible = True" I don't get a Word
window appearing.
Is wdApp instantiated and can you get object variable "doc" instantiated as
well ...?

Not quite sure what you mean here, I'm afraid I'm complete beginner
with VB

cheers

Finlay
 
P

Perry

I tried this already, "Set appWord = New Word.Application" does start
a new WINWORD.EXE process but I can't seem to do anything with it, eg
if I follow that line with "appWord.Visible = True" I don't get a Word
window appearing.

That's strange.

Let's see whether yr system allows you to do something completely basic as
in:

sub testingword()
Dim wdapp as new word.application
dim doc as word.document
wdapp.visible = true
set doc = wdapp.documents.add
end sub

Do you see the newly created document?
 
F

fmackay

That's strange.

Let's see whether yr system allows you to do something completely basic as
in:

sub testingword()
Dim wdapp as new word.application
dim doc as word.document
wdapp.visible = true
set doc = wdapp.documents.add
end sub

Do you see the newly created document?

This breaks at line "wdapp.visible=true" with error 80040155
"automation error - interface not recognised".

Dim wdapp As Word.Application
Set wdapp = New Word.Application

breaks at the second line with the same error, while

Dim wdapp As Object
Set wdapp = CreateObject("Word.Application")

gives error 424 "object required"

Trying Excel instead of Word doesn't work either - I think there's
something wrong with the office installation on this machine and I
probably need to call our IT dept in.

Many thanks for your help up to this point,

Finlay
 
P

Perry

Your MS Office installation got corrupt.
I would advise a full re-installation.

If it concerns an enterprise rollout of Office, you will need to talk to the
IT ops department for this.

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top