Reference problem vba

  • Thread starter Thread starter Gina
  • Start date Start date
G

Gina

Hi.

if vba doesn't 'understand' word.application

--> Dim wrd as word.application ' here I get userdefined type

think that may be a missing reference , but which ?

TIA for your help
Gina
 
opend my program in access 2002 but coded it in access 2k
when i reopened it in 2k it refs for word and excel 10 object library showed
up as 'not installed'

just then deselected the 'not installed' ones .....

if a db is once opened and saved on e.g. 2002
will i always have these kind of problems .... when it is coded in an
earlier version ?

Gina
 
Hi Gina,

This is a fairly frequent problem. If you need your program to work
reliably across multiple versions of Office, it's usually best to use
late binding for all the OLE Automation. What you have now - references
and Dim wrd As Word.Application - is early binding. For late binding,
remove the reference to the Word and Excel object libraries, replace
Dim wrd As Word.Application
with
Dim wrd As Object 'Word.Application
and so on, and also replace all Word and Excel constants (e.g.
wdLineSpaceDouble) with the equivalent values (e.g. 2).

I always use early binding when programming, because Intellisense, the
Object Browser and the compiler all help avoid and detect errors. But
once the code is working I often modify it to use late binding to make
it more reliably portable between systems.
 
Hi John,

Thanks for your answer .... I understand what you mean ...

so I replaced

Dim wrd As Word.Application with
Dim wrd As Object

I refer to my 'wrd' in several functions

template = CurrentProject.Path & "\invoice.dot"
Set wrd = New Word.Application
Set DC = wrd.Documents.Add(template)

How - after it is an Object now - can I refer to word
??
Gina
 
Mostly, there's no change. The main difference is that you can't use
New, but have to use CreateObject() or GetObject()

Dim wrd As Object 'Word.Application
Dim DC As Object 'Word.Document

...
Set wrd = CreateObject("Word.Application")
Set DC = wrd.Documents.Add(template)
...

Hi John,

Thanks for your answer .... I understand what you mean ...

so I replaced

Dim wrd As Word.Application with
Dim wrd As Object

I refer to my 'wrd' in several functions

template = CurrentProject.Path & "\invoice.dot"
Set wrd = New Word.Application
Set DC = wrd.Documents.Add(template)

How - after it is an Object now - can I refer to word
??
Gina
 
Thanks a lot, John !!!!
you were very helpful to me ... and not the first time!!

Gina

John Nurick said:
Mostly, there's no change. The main difference is that you can't use
New, but have to use CreateObject() or GetObject()

Dim wrd As Object 'Word.Application
Dim DC As Object 'Word.Document

...
Set wrd = CreateObject("Word.Application")
Set DC = wrd.Documents.Add(template)
...

Hi John,

Thanks for your answer .... I understand what you mean ...

so I replaced

Dim wrd As Word.Application with
Dim wrd As Object

I refer to my 'wrd' in several functions

template = CurrentProject.Path & "\invoice.dot"
Set wrd = New Word.Application
Set DC = wrd.Documents.Add(template)

How - after it is an Object now - can I refer to word
??
Gina

John Nurick said:
Hi Gina,

This is a fairly frequent problem. If you need your program to work
reliably across multiple versions of Office, it's usually best to use
late binding for all the OLE Automation. What you have now - references
and Dim wrd As Word.Application - is early binding. For late binding,
remove the reference to the Word and Excel object libraries, replace
Dim wrd As Word.Application
with
Dim wrd As Object 'Word.Application
and so on, and also replace all Word and Excel constants (e.g.
wdLineSpaceDouble) with the equivalent values (e.g. 2).

I always use early binding when programming, because Intellisense, the
Object Browser and the compiler all help avoid and detect errors. But
once the code is working I often modify it to use late binding to make
it more reliably portable between systems.

 
Back
Top