PRB: Type Mismatch When Passing Variants to Word Using OLE (137096)
The information in this article applies to:
- Microsoft Visual Basic Standard Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Professional Edition, 16-bit, for Windows 4.0
- Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0
This article was previously published under Q137096 SYMPTOMS
When trying to pass a Variant data type to Microsoft Word using OLE
automation, a "Type mismatch" error occurs. For example, if objVar is an
object variable set to a Word.Basic object, and Text1 is some text box
containing a string value, the following line of code generates the error:
objVar.Insert Text1
This problem did not exist in Visual Basic version 3.0, so it must be taken
into consideration when doing any code porting and/or upgrading.
RESOLUTION
To avoid this problem, the variable passed to Word must be explicitly
typed. The previous example can be replaced by either of the following to
prevent this error:
objVar.Insert Text1.Text
objVar.Insert CStr(Text1)
STATUS
This behavior is by design
Modification Type: | Major | Last Reviewed: | 12/9/2003 |
---|
Keywords: | kbprb kbProgramming KB137096 kbAudDeveloper |
---|
|