ACC2: Using MS Word Spelling & Grammar Tools in MS Access

Last reviewed: June 3, 1997
Article ID: Q132185
The information in this article applies to:
  • Microsoft Access version 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:

  1. Create a new form based on the table containing the MyOle field, using the AutoForm Wizard.

  2. 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
    

  3. 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
    
    

  4. 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 : AutoGnrl IntpOlea kbole
Technology : kbole
Version : 2.0
Platform : WINDOWS
Hardware : X86
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 3, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.