[AccessD] Runtimes - Preferably AccessXP but2003ifabsolutelyrequired

Bryan Carbonnell carbonnb at gmail.com
Tue Jan 30 06:39:24 CST 2007


On 1/29/07, Rocky Smolin at Beach Access Software
<rockysmolin at bchacc.com> wrote:

> I'm still having trouble with a user opening a word doc and the code works
> here.  So I'm switching to late binding.
>
> Would the correct code for late binding be:
>
> Dim objWord As Object
> Set objWord = GetObject("", "Word.Application")

Rocky,

GetObject will only work if you have Word open. It will fail miserable
if Word isn't.

Here is how I deal with it:

dim objWord as Object

'Get Word Object
'Bypass error handling
On Error Resume Next
'Reuse Word object if open
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then ' Check to see if we got a Word Object
    'Don't have a Word Object, so we need to create one
    Set objWord = CreateObject("Word.Application")
End If
'Reset Error Handling
On Error GoTo 0

What this chunk does is tries to reuse an open Word instance. If there
is no Word instance it will create one.

-- 
Bryan Carbonnell - carbonnb at gmail.com
Life's journey is not to arrive at the grave safely in a well
preserved body, but rather to skid in sideways, totally worn out,
shouting "What a great ride!"



More information about the AccessD mailing list