ACC2: Using MS Word Spelling & Grammar Tools in MS Access
ID: Q132185
|
The information in this article applies to:
-
Microsoft Access 2.0
-
Microsoft Word for Windows, version 6.0
SUMMARY
This article demonstrates how you can use Access Basic code to activate the
Spelling and Grammar tools in Microsoft Word for Windows version 6.0 for
an embedded Microsoft Word document in Microsoft Access.
This article assumes that you are familiar with Access Basic and with
creating Microsoft Access applications using the programming tools provided
with Microsoft Access. For more information about Access Basic, please
refer to the "Building Applications" manual.
MORE INFORMATION
The following example assumes you have a Microsoft Access table with an OLE
field called MyOle that contains embedded (not linked) Microsoft Word
objects.
To use Access Basic code to activate the Microsoft Word Spelling and
Grammar tools for an embedded OLE object in a form, follow these steps:
- Create a new form based on the table containing the MyOle field, using
the AutoForm Wizard.
- On the View menu, click Code, type the following line in the
Declarations section of the Module window, and then close the
Module window:
Option Explicit
- Add a command button to the form and name it SpellCheck. Set the command
button's OnClick property to the following event procedure:
Sub SpellCheck_Click ()
On Error GoTo SpellCheck_Err
Dim WordObj As Object
' Set the object variable to the form's embedded OLE control.
Set WordObj = Me![MyOle].Object.Application.WordBasic
' Activate the embedded control.
MyOle.Action = 7
' Specify a WordBasic function to perform.
WordObj.ToolsSpelling
' Deactivate the embedded control.
MyOle.Action = 9
Exit Sub
SpellCheck_Err:
If Err = 2763 Then
MsgBox "The Spell Check is Complete."
Resume Next
End If
End Sub
- Add a command button to the form and name it GrammarCheck. Set the
command button's OnClick property to the following event procedure:
Sub GrammarCheck_Click ()
On Error GoTo GrammarCheck_Err
Dim WordObj As Object
' Set the object variable to the form's embedded OLE control.
Set WordObj = Me![MyOle].Object.Application.WordBasic
' Activate the embedded control.
MyOle.Action = 7
' Specify a WordBasic function to perform.
WordObj.ToolsGrammar
'Deactivate the embedded control.
MyOle.Action = 9
Exit Sub
GrammarCheck_Err:
If Err = 2763 Then
MsgBox "The Grammar Check is Complete."
Resume Next
End If
End Sub
NOTE: The error trapping shown above is necessary to avoid an alert
message in Microsoft Access. When Microsoft Word completes spelling or
grammar checking, it returns a message reporting that the check is
complete. Microsoft Access interprets this as an error and generates the
following message that you can resolve using error trapping:
Microsoft Word returned the following error:
Microsoft Word - The spelling check is complete.
REFERENCES
For more information about OLE Automation, search for "OLE Automation," and
then "Interoperability with Microsoft Word and Microsoft Excel(Common
Questions)" using the Microsoft Access Help menu.
For more information about WordBasic commands available through OLE
Automation, search for "WordBasic," and then "WordBasic Help" using the
Microsoft Word for Windows version 6.0 Help menu.
Additional query words:
Word.Basic documents embedding linking
Keywords : kbole IntpOlea
Version : 2.0
Platform : WINDOWS
Issue type : kbinfo