Solved

Illegal operation error while exporting data to MS Word.

Posted on 2003-11-06
12
177 Views
Last Modified: 2010-05-03
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

0
Comment
Question by:morye
  • 6
  • 4
12 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9693326
Function doesn't contain error handling. Add error handling with detailed error description and run program again.
0
 

Author Comment

by:morye
ID: 9694016
I had added the error handle, but the error still exist.
0
 
LVL 5

Expert Comment

by:IThema
ID: 9694030
...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.
0
 

Author Comment

by:morye
ID: 9694139
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


0
 

Author Comment

by:morye
ID: 9694178
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~~~
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:IThema
ID: 9694239
... 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.
0
 

Author Comment

by:morye
ID: 9694355
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.
0
 
LVL 5

Expert Comment

by:IThema
ID: 9694535
Maybe a strange question, but is this client's computer significantly slower than the other computers?
0
 

Author Comment

by:morye
ID: 9698233
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~~~
0
 
LVL 5

Accepted Solution

by:
IThema earned 200 total points
ID: 10163128
I completely forgot about this question. Sorry for that.
Rereading this question made me think of a situation I had myself a while ago. However, I don't recall that having anything to do with kerner.dll.

My problem was solved by completely uninstalling Office before re-installing it. If that doesn't help and there really is something with the kernel and if really all computers have the same windows OS, the same Service Pack and the same Office version then I'd simply recommend you to re-install the entire computer. The fact that your error handler doesn't catch any error means your application is OK to me.

I hope you already solved your problem, otherwise you could try the things I stated above.

Cheers and good luck...
0
 

Author Comment

by:morye
ID: 10250913
Thank you very much.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now