object variable or with block variable not set

K

Keith

I'm running XP SP3 and Office 2003 SP3. I have 2GB RAM and tons of drive
space.

Same app, same code, etc. on my machine as on my clients' machines.

Here's an excerpt of my code. When the line "Set docWord =
objWord.Documents.Add(Template:=sWordFormsPath & "evidence.dot")" runs as in
the code below:

Option Compare Database
Option Explicit

'Global mywordform As Object
Global objWord As Word.Application
Global docWord As Word.Document
Global rngWord As Word.Range

Public Sub blahblah()
...
...

Call subOpenWord

Set docWord = objWord.Documents.Add(Template:=sWordFormsPath &
"evidence.dot")
...
...
...
End Sub

Public Sub subOpenWord()

On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number > 0 Then
Set objWord = CreateObject("word.application")
objWord.Visible = True
objWord.WindowState = wdWindowStateMaximize
End If

End Sub

Word is running in the background before this point.

I get the error "object variable or with block variable not set".

I tried some of the solutions here: http://support.microsoft.com/kb/319832
but this seems like a total waste of time since it's all working fine on
several machines at 2 separate client offices. Something's amiss on my
machine or my Office setup or ????

Thanks,

Keith
 
K

Keith

What do you mean "not initialized it"? Are you talking about something apart
from my call to subOpenWord()?

The thing is that this all runs perfectly on 2 separate clients on all dozen
or so machines in each office.

Keith
 
K

Klatuu

Sorry, I totally misread your post.
If it is running on you machine, but not your client's machines, there is
most likely a VBA reference missing. Check to ensure you have a reference
set to the Word object library.
 
K

Keith

The reference is there. It compiles fine. I even tried moving it up in the
list but that didn't help.
 
K

Keith Wilby

Keith said:
I'm running XP SP3 and Office 2003 SP3. I have 2GB RAM and tons of drive
space.

Same app, same code, etc. on my machine as on my clients' machines.

Is the offending machine up to date with service packs and what-not?

Keith.
www.keithwilby.co.uk
 
K

Keith

Yes. At the very beginning of my post I specified that Windows XP is SP3 and
Office 2003 is SP3. One of the client's is running the same exact
configuration in fact. All MS stuff is fully up to date as of a couple of
days ago and the client has auto MS updates running on all machines so we
should be running same exact Windows and Office versions.
 
K

Keith

Interestingly when I remove the Word 11 reference and change all my
enumerations to numerals instead of words (like wdCell = 1 for example) it
works fine but then I get other weird errors (see my other post from
yesterday "type mismatch error in word automation") and that's a lot of work
because there are a lot of enumerations to change. I don't want to go that
route. Seems completely unecessary since client machines run fine.
 
K

Keith

Something new. I commented out the OpenWord code so it's running as
folllows:


Public Sub subOpenWord()

' On Error Resume Next
' Set objWord = GetObject(, "Word.Application")
' If Err.Number <> 0 Then
Set objWord = Nothing
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.WindowState = wdWindowStateMaximize
' End If

End Sub

Now, on the line "Set objWord = CreateObject("Word.Application")" I get the
follwoing error:

Automation Error
Library not Registered.

Okay, Word 11 is in the references and it's not MISSING. Any ideas on this?
What's more is what I mentioned in another part of this thread is that my
code compiles just fine (wiht all my enumerations and references to Word).
So what's the deal? Anyone familiar with this problem?

Keith
 
K

Keith

The really crazy thing is that if you watch the windows processes when this
code runs, WINWORD.exe does show up in there when it wasn't there before
that code ran (all instances of word were closed prior to running the code
below).
 
K

Keith

Well I think I found the problem. I found a post on another forum that
mentions Word 12 references in the registry. I deleted the one he mentioned
and that took care of part of the problem but there are other places in code
now that create similar errors. I backed up the registry and did a search on
it and there are TONS of references to Office 12 tools (outlook, word,
excel, etc) which mystifies me. I bought this machine last year. It had a
trial of Office 2007 (versoin 12) on it. I took it off and installed 11.
THis sucks because I have a feelign that all these office 12 references are
really screwing things up. I'm a bit nervous about removing all those
registry entries. There are about 200 of them.
 
K

Keith

And since I have VS2008 installed which I think installs some things for
office 2007 (interop assy's maybe but not sure) I think I'm screwed.
Deleteing all those references seems like it could be a big mistake for
other htings. Any ideas?
 
K

Keith

As it turns out, the problem was that there were registry entries for Word
12 due to the demo installation and Access was confused. But I never
uninstalled all of it. The Office 2007 Interop Assemblies was still
installed. I compared the installed files and registry from a computer that
also had Office 2003 and VS 2008 on it but that never had Office 2007
installed. So I found it was safe to uninstall the Office 2007 Interop
Assemblies. Once I did that the registry no longer had any references to
Word 12. now the code runs just as it did before.

Keith
 

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