Runtime Error 52

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am running the following code to open Microsoft word, and get a run time
error 52. This code works fine on Word 2003, however when used on another
computer to open Word 2002 it gives me the error (I adjust the path name to
OFFICE10 when going to 2002. I have loaded patches, but these haven't fixed
the problem.

How do I get it to work?

Private Sub Option2_Click()
On Error GoTo Err_Option2_Click

DoCmd.SetWarnings False
DoCmd.OpenQuery "KS_BoxLabels_QMT", acViewNormal, acEdit
Call Shell("C:\Program Files\Microsoft Office\OFFICE11\winword.exe", 1)
DoCmd.SetWarnings True


Exit_Option2_Click:
Exit Sub

Err_Option2_Click:
MsgBox Err.Description
Resume Exit_Option2_Click
End Sub
 
Hi Penstar

Are the paths to the winword.exe files correct? On my PC the paths to the
Word file are c:\msword\office10\winword.exe, c:\msword\office11\winword.exe
etc.

Just a thought.

BW
 
Hi

Another thought.

If you don't know where Word resides on the other PC's - likely if you are
installing to remote locations, then you could launch Word as an object to
get around the problem:

Set objWord = New Word.Application
objWord.Visible = True

Cheers.

BW
 
Thanks for your ideas. I definitely have the correct path names.

I tried the code you suggested - it said "User-defined type not defined"
and highlights "New Word.Application" in the code?
 
You need to set a reference to the Word library file:

- In any module click on Tools > References
- scroll down and check the Microsoft Word 11.0 Object Library. Click OK
- Click on Debug - Compile.

The code should now compile and run properly.

Good luck.

BW
 
Or, since you don't know which version a given user will have, try Late
Binding.

Dim objWord As Object

Set objWord = CreateObject("Word.Application")
objWord.Visible = True

No reference need be set.
 
Thanks Douglas and BW

I have taken what you have suggested a step further, and got a complete
merge working!

Dim objWord As Object
Set objWord = GetObject("C:\Documents and Settings\BoxLabelstest1.doc")
objWord.Application.Visible = True
objWord.MailMerge.Execute
objWord.Close

I have since found out that my initial runtime error was with a conflict in
a word startup file from another program (MYOB).

Penny
 
Back
Top