Link to home
Start Free TrialLog in
Avatar of morye
morye

asked on

Illegal operation error while exporting data to MS Word.

In my VB program, it contains a function to export a ADODB recordset to MS Word. (MS Access DB)

It work fine on other computers. However, in one computer (Win2000), an error message appears...
"This program has performed an illegal operation and will be shut down."

It said is the problem with kernel32.dll.


Please help~~



The source codes are...

Public wrdApp      As Word.Application
Public wrdDoc      As Word.Document
Public wrdSelection    As Word.Selection

public functiob ExportWord()

    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = True
   
    ' Add a new document
    Set wrdDoc = wrdApp.Documents.Add
    wrdDoc.Select
    Set wrdSelection = wrdApp.Selection
    wrdSelection.PageSetup.LeftMargin = 50
    wrdSelection.PageSetup.RightMargin = 50

. . . ..

    wrdDoc.Saved = True
   
    ' Release References
    Set wrdSelection = Nothing
    Set wrdDoc = Nothing
    Set wrdApp = Nothing
end function

Avatar of AlexFM
AlexFM

Function doesn't contain error handling. Add error handling with detailed error description and run program again.
Avatar of morye

ASKER

I had added the error handle, but the error still exist.
...or debug and specify the location this error occurs. What Word version have you got? And what Word object library is referenced? Version 8 (Office '97) or 9 (Office 2000)???

btw: always handle errors while modifying print-settings. If no printer is installed on your system or your system cannot connect to a printer (for example: laptop from the company, not attached to network anymore can't find a printer) then an error will occur when you're trying to set the printer orientation for example.
Avatar of morye

ASKER

The word version is Office 2000.

I can't use error handle to handle the error.

the code is...

public functiob ExportWord()
On error goto errH


Avatar of morye

ASKER

srory, wrong post....


The word version is Office 2000.

I can't use error handle to handle the error.

the code is...

public functiob ExportWord()
On error goto errH
...
...
.
exit function

errH:
  msgbox err.Number & vbcrlf & err.description
end function

The error wasn't display with the message box. It seems to be is a window error.


Thank you~~~
... and you say it's only one computer? Re-installing MS Office MIGHT help. My reason to believe that is because you say it's only one computer and that the error handling doesn't handle the error...

But still one more thing before you might re-install Office (word): Can you debug the application? Please state then on what line of code the error message pops up.
Avatar of morye

ASKER

Before I posted this question, I already re-installed the MS Office....but, it still not works...

The situation is I had install the VB to program to several computers. But, only one computer have this error appear.

According it's my client's computer,  I can't install the Visual basic to the computer. So, it's not easy to state each line.

However, I think the error is appear between these lines..

    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = True
   
    ' Add a new document
    Set wrdDoc = wrdApp.Documents.Add

because the MS Word is open, but haven't any new word file create.

Thank You.
Maybe a strange question, but is this client's computer significantly slower than the other computers?
Avatar of morye

ASKER

no~
All the computers (at the before) is the same setting.
But, all computers have use for a period.
I don't know how the user use it.

He maybe install or remove some porgrams himself. It makes some setting files changed......etc.


Please help~~~
ASKER CERTIFIED SOLUTION
Avatar of IThema
IThema

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of morye

ASKER

Thank you very much.