Share via

Can I trigger SpellCheck programatically in Access 2007?

Anonymous
2010-06-05T15:22:02+00:00

Is there a way to use VBA to trigger spellcheck in an Access 2007 application?  I have an app where the user has to enter quite a bit of text that needs to be quality checked even though they do not have access to the Ribbon.  Is it possible to use VBA or macro to trigger the Spellcheck capability?

Thanks,

Ne3Can

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-06-07T14:15:22+00:00

Here is the VBA code that should work.  I have not tested it in 2007 or 2010.

This code uses a button and spell checks one specific control on the current record.

Private Sub cmdSpellCheck_Click()

    With Me!txtDescription

        .SetFocus

        .SelStart = 0

        .SelLength = Len(Me!txtDescription)

    End With

    DoCmd.RunCommand acCmdSpelling

End Sub

Public Function fSpell()

'*******************************************

'Name:      fSpell (Function)

'Purpose:   Spell check current field or fields.

'Author:    John Spencer UMBC-CHPDM

'Date:      October 31, 2002, 01:15:31 PM

'Control on form must be a textbox and have tag property

'that contains the phrase "SpellCheck"

'*******************************************

Dim ctlSpell As Control

Dim frm As Form

On Error GoTo fSpell_Error

   Set frm = Screen.ActiveForm

   Set ctlSpell = frm.ActiveControl

      With ctlSpell

         If InStr(1, Nz(.Tag), "SpellCheck", vbTextCompare) <> 0 And _

            .Locked = False And _

            .Enabled = True And _

            TypeOf ctlSpell Is TextBox And _

            Len(Trim(ctlSpell & vbNullString)) > 0 Then

            .SetFocus

            .SelStart = 0

            .SelLength = Len(ctlSpell)

            DoCmd.RunCommand acCmdSpelling

         End If

      End With

Exit Function

'---------------------------------------------------------------------

'---------------------------------------------------------------------

'    Alternative code to check every textbox control on form

'---------------------------------------------------------------------

'---------------------------------------------------------------------

   Set frm = Screen.ActiveForm

   DoCmd.SetWarnings False

   ' Step through Controls collection

   For Each ctlSpell In frm.Controls

      If TypeOf ctlSpell Is TextBox Then  'Only check textbox controls

         With ctlSpell

               If Len(Trim(ctlSpell & vbNullString)) = 0 Then  'Only check if there is data in control

               ElseIf .Locked = True Then  'Don't Spell check if control is locked

               ElseIf .Enabled = False Then  'Don't check if control is not enabled

               ElseIf InStr(1, Nz(.Tag), "Spellcheck", vbTextCompare) = 0 Then

               'Don't check if control is not marked to be checked

               Else  'passed all the tests, so spell check

                 .SetFocus

                 .SelStart = 0

                 .SelLength = Len(ctlSpell)

                 DoCmd.RunCommand acCmdSpelling

               End If  'test control for problems

            End With  'ctlSpell

      End If  'textbox

  Next  'Check the next control

   DoCmd.SetWarnings True

fSpell_Exit:

   Exit Function

fSpell_Error:

   If Err.Number = 2474 Then

      'No Active control on current form

      'Therefore we shouldn't be spellchecking

   Else

      MsgBox Err.Number & ": " & Err.Description, , "Error in fSpell (Spell Check Routine)"

   End If

   Resume fSpell_Exit

End Function


John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2010-06-05T16:09:15+00:00

    On Sat, 5 Jun 2010 15:22:02 +0000, Ne3Can wrote:

    Then give them access to the Ribbon. At least a custom one with the

    features you need users to have.

    You can also try F7, unless you are intercepting that as well :-)

    -Tom.

    Microsoft Access MVP

    >

    >

    >Is there a way to use VBA to trigger spellcheck in an Access 2007 application? I have an app where the user has to enter quite a bit of text that needs to be quality checked even though they do not have access to the Ribbon. Is it possible to use VBA or macro to trigger the Spellcheck capability?

    >

    >Thanks,

    >

    >Ne3Can


    -Tom. Microsoft Access MVP

    Was this answer helpful?

    0 comments No comments