A family of Microsoft relational database management systems designed for ease of use.
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