| Re: How Do I Invoke Spell Check from Within Access VBA 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!
Last edited by LauryBurr; 04-Nov-2008 at 18:13 PM.
Reason: Found more information
|