If something is selected the spell check button will check just the
selection. If something is not selected, the spell check button will check
every field in every record in the recordset.
Here is are two code examples that I use to check items. I believe Arvin
Meyers at DataStrat has an example also.
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
Center for Health Program Development and Management
University of Maryland Baltimore County
..