Hi WolfPack,
Here is a function that was previously posted by Access MVP Arvin Meyer. If
you place this into a module, you can call it from any form:
Option Compare Database
Option Explicit
Public Function Spell()
' Arvin Meyer 9/17/1998
' Adapted from code by Terry Wickenden
Dim ctlSpell As Control
Dim frm As Form
Set frm = Screen.ActiveForm
DoCmd.SetWarnings False
' Enumerate Controls collection.
For Each ctlSpell In frm.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 Function
You can call the Spell function from a command button on a form. For example:
Private Sub cmdSpellCheck_Click()
On Error GoTo ProcError
Call Spell
ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, , _
"Error in cmdSpellCheck_Click event procedure..."
Resume ExitProc
End Sub
You could also call it automatically, by using the Form's AfterUpdate event
procedure:
Private Sub Form_AfterUpdate()
On Error GoTo ProcError
Call Spell
ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in Form_AfterUpdate procedure..."
Resume ExitProc
End Sub
However, in this case, it will only be called if you dirty a record by
editing it. My only suggestion to the function, as given, is that you might
want to add error handling and ensure that warnings are turned back on even
if the function does not run to completion for any reason. For example:
Public Function Spell()
On Error GoTo ProcError
<rest of code goes here, except move the statement to turn warnings back on
to the ProcError label, as indicated below>
ExitProc:
DoCmd.SetWarnings True
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Spell..."
Resume ExitProc
End Function
Tom
http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
:
How do you set a form to spell check a "record" only, without continuing to
check the entire database? I want to create a function that checks spelling
after a user enters data in a field (before they exit the record).