Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

How Do I Invoke Spell Check from Within Access VBA

Discussion in 'Information Technology' started by EarlCPhillips, Jul 28, 2006.

  1. EarlCPhillips

    EarlCPhillips
    Expand Collapse
    Guest

    User wants to invoke spell check for fields within a table since data entry
    spelling is variable. How do I do this from within VBA?
    Earl Phillips
    Volunteer Programmer
    Harvesters Community Food Bank
    --
    Trying To Feed The Hungry
     
  2. Loading...


  3. Steve Schapel

    Steve Schapel
    Expand Collapse
    Guest

    Earl,

    DoCmd.RunCommand acCmdSpelling

    Note that this invokes the Office spell-ckecker, and relies on an Office
    installation of the same version as the Access installation. Also note
    that this code is often best run from a Command Button... if you use the
    After Update event of a control or form or whatever, the spelling
    checker runs even if there are no errors detected, which can be annoying.

    --
    Steve Schapel, Microsoft Access MVP

    EarlCPhillips wrote:
    > User wants to invoke spell check for fields within a table since data entry
    > spelling is variable. How do I do this from within VBA?
    > Earl Phillips
    > Volunteer Programmer
    > Harvesters Community Food Bank
     
  4. LauryBurr

    LauryBurr
    Expand Collapse
    SPNer

    Joined:
    Nov 4, 2008
    Messages:
    1
    Likes Received:
    0
    There's another way to avoid the spell-checker telling you every time the spell check revealed no error - notte the extra code before & after calling the spellchecker.

    DoCmd.SetWarnings False
    DoCmd.RunCommand acCmdSpelling
    DoCmd.SetWarnings True

    Now, some of you might panic at this point. but don't worry - if there IS an error it'll tell you, but if not it just lets you get on with life!

    So this is the best code to use as - for example - an "on lost focus" event. n my experience, if you give people the option to spellcheck (e.g. with a button) not everyone will use it - including those whose spelling is, let's say, less than perfect.

    But note that the spellcheck command (whether as used here or with a separate button) will spellcheck the whole form, not just the current text box. Now, if you need to do that (address fields probably have so many words not in your dictionary that the spellcheck would be frustrating if it picked up every line of the address as an "error" - it'd certainly slow down data entry) then try the following, more comprehensive coding:

    Private Sub YOURFIELDNAME_Exit(Cancel As Integer)
    Dim strSpell
    strSpell = YOURFIELDNAME
    If IsNull(Len(strSpell)) Or Len(strSpell) = 0 Then
    Exit Sub
    End If
    With YOURFIELDNAME
    .SetFocus
    .SelStart = 0
    .SelLength = Len(strSpell)
    End With
    DoCmd.SetWarnings False
    DoCmd.RunCommand acCmdSpelling
    DoCmd.SetWarnings True
    End Sub

    For this I owe thanks to “icezebra” at this url: http://www.access-programmers.co.uk/forums/showthread.php?t=130780. He's actually provided the answer that I was looking for when I found this site!
     
    #3 LauryBurr, Nov 4, 2008
    Last edited: Nov 4, 2008

Share This Page