Code Examples

Spell Checking in Runtime Environment

acCmdSpelling

To use Spell Checking in a runtime environment, you must write a procedure to run the installed spelling checker already on your user's computer or look for a 3rd party add-on that does spell checking. If Microsoft Word 97 is installed on your user's computer, you can write a procedure for a command button's OnClick property.

The following 2 examples of code can be attached to the OnClick property of a command button called cmdSpell. The first example checks the contents of a single control. The second spell checks the entire form.

'************ Code Example 1 Start ****************
' Adaptation by Terry Wickenden of code
' from Microsoft Knowledge Base


Private Sub cmdSpell_Click()
  Dim ctlSpell As Control

  Set ctlSpell = Screen.PreviousControl
  If TypeOf ctlSpell Is TextBox Then
    If IsNull(Len(ctlSpell)) Or Len(ctlSpell) = 0 Then
      MsgBox "There is nothing to spell check."
      ctlSpell.SetFocus
      Exit Sub
    End If
    With ctlSpell
      .SetFocus
      .SelStart = 0
      .SelLength = Len(ctlSpell)
    End With
    DoCmd.RunCommand acCmdSpelling
  Else
    MsgBox "Spell check is not available for this item."
  End If
  ctlSpell.SetFocus
End Sub
' ****************** Code Example 1 End ********************

' ***************** Code Example 2 Start *******************
' Adaptation by Terry Wickenden of code
' from Microsoft Knowledge Base
' additional suggestions from Arvin Meyer


Private Sub cmdSpell_Click()
  Dim ctlSpell As Control

  DoCmd.SetWarnings False
  ' Enumerate Controls collection.
  For Each ctlSpell In Me.Controls
    If TypeOf ctlSpell Is TextBox Then
      If Len(ctlSpell) > 0 Then
        With ctlSpell
          .SetFocus
          .SelStart = 0
          .SelLength = Len(ctlSpell)
        End With
        DoCmd.RunCommand acCmdSpelling
      End If
    End If
  Next
  DoCmd.SetWarnings True
End Sub

' ****************** Code Example 2 End ********************

© 1998 - 2011 Terry Wickenden TKW Design Site developed, maintained and hosted by TKW Design. This site is best viewed at 1024 x 768. Optimised for Firefox.