Selective use of Spellchecker to ignore forename



I use a standard spell checker routine on various forms to check selected
controls only. This is based on standard code : DoCmd.RunCommand
acCmdSpelling in a subroutine SpellCheckControl


Public Sub SpellCheckControl(ctlSpell As Control)
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True
End Sub

For example to spellcheck all records in controls ‘Report’ & ‘Target’ ONLY,
I have:
Private Sub btnSpellCheck_Click()
DoCmd.GoToRecord , , acFirst
SpellCheckControl Me.Report
SpellCheckControl Me.Target
End Sub

So for example, I deliberately do not check the Forename field as this isn’t
needed and would waste a lot of time

However if the user enters the forename in the selected Report or Target
controls, it will be spell checked which is a nuisance.

Ideally, I want to ignore the forename (if correctly spelt for that record)
when spellchecking the Report & Target controls. Can this be done?

The other possible approach would be to add the forenames to the custom
dictionary automatically without showing the dialog box. I’d prefer not to do
this as it will then allow through incorrect spellings for the individual
record concerned

Any ideas please?

Jack Leach

This is just a shot in the dark (I don't get into this stuff much myself),
but I think maybe if you use the controls' SelStart and SelEnd properties to
select a particular portion of the control's text, you can run the spellcheck
only on the selected text?

If I've got that right, maybe you could set up a routine that selects the
portion of the text you want (looking for spaces to find out where to start
the selection), and run it like that.

Might be worth a shot.
Jack Leach

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)


Hi Marshall

You are of course quite right about the SpellCheckcontrol code I sent being
incomplete. I had edited it before sending - my actual code does actually
reference ctlSpell

Public Sub SpellCheckControl(ctlSpell As Control)

If TypeOf ctlSpell Is TextBox Then
If ctlSpell.Locked = False And ctlSpell.Visible = True Then
If IsNull(Len(ctlSpell)) Or Len(ctlSpell) = 0 Then
'MsgBox "There is nothing to spell check."
Exit Sub
End If
With ctlSpell
.SelStart = 0
.SelLength = Len(ctlSpell)
End With
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True
End If
MsgBox "Spell check is not available for this item."
End If
End Sub

I have now fixed the problem I asked about earlier
To do so, I replace all instances of the person's Forename entered in the
controls being spell checked with the string with the string 'Forename', run
the spell check & then revert the string back to the ac tual name afterwards

There is a bit more to it... but if anyone is interested this is the rest of
the code.
The fields being checked are 'Comment' and 'Action'
Note the use of a trailing space to avoid confusing words such as 'same'
with the name Sam

Private Sub RunSpellCheck()
'run spell check without message boxes
'CR v4610W - modified to exclude checking Forename in selected fields

'temporarily replace all instances of forename in selected fields so ignored
by spellchecker
strText = Me.Forename & " " 'add space to overcome errors e.g. avoid
'same' being confused for Sam
Me.Comment = Replace([Comment], strText, "Forename ")
Me.Action = Replace([Action], strText, "Forename ")

'Run spellcheck
SpellCheckControl Me.Comment
SpellCheckControl Me.Action

'Restore all instances of forename in selected fields
Me.Comment = Replace([Comment], "Forename ", strText)
Me.Action = Replace([Action], "Forename ", strText)
strText = ""

End Sub


Private Sub cmdSpellCheck_Click() 'CR - NEW v4575W

'CR v4610W - modified to exclude checking Forename in selected fields
'SpellCheckControl Me.Comment
'SpellCheckControl Me.Action
RunSpellCheck 'CR v4610W
MsgBox "Spell check complete...", vbExclamation, "New Pastoral Record
Spell Check"

End Sub

I have now successfully adapted this for several forms
It could of course be extended to also exclude other items you don't want to
check e.g. Surname or other data entered in the control being checked

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question