Selective use of Spellchecker to ignore forename

R

ridders

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?
 
M

Marshall Barton

ridders said:
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


Sorry, but in my experience that code will check all fields
in all records in the form's recordset. Your
SpellCheckControl procedure never uses the ctlSpell argument
so I can't see how you can expect it to check a specific
control's value.

I guess it might work if the form is not bound to a
table/query and the two text boxes are the only text boxes
on the form. But I have not explored that kind of
arrangement because it seems like combox boxes would be
better than text boxes

To check one item in a bound form, I have always needed to
select the text before running spell check:

Public Sub SpellCheckControl(ctlSpell As Control)

ctlSpell.SetFocus
ctlSpell.SelStart = 0
ctlSpell.SelLength = Len(ctlSpell.Value)

DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True
End Sub

I did not follow whatever you were trying to say about the
forename or what logic could be used to decide whether to
check a value or not.
 
J

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
www.tristatemachine.com

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

ridders

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."
ctlSpell.SetFocus
Exit Sub
End If
With ctlSpell
.SetFocus
.SelStart = 0
.SelLength = Len(ctlSpell)
End With
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True
End If
Else
MsgBox "Spell check is not available for this item."
End If
ctlSpell.SetFocus
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
 
M

Marshall Barton

Ahhh, now I see what problem you were trying to solve and
your approach is a good one. IMO, most of the code looks
fine, but I think I would do the SpellCheckControl procedure
a little differently:

Public Sub SpellCheckControl(ctlSpell As Control)
With ctlSpell
If .ControlType = acTextBox Then
If Not .Locked And .Visible Then
If Len(Nz(ctlSpell,"") = 0 Then
'MsgBox "There is nothing to spell check."
.SetFocus
Exit Sub
End If
.SetFocus
.SelStart = 0
.SelLength = Len(.Value)
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True
End If
Else
MsgBox "Spell check is not available for this item."
End If
.SetFocus
End With
End Sub
--
Marsh
MVP [MS Access]

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."
ctlSpell.SetFocus
Exit Sub
End If
With ctlSpell
.SetFocus
.SelStart = 0
.SelLength = Len(ctlSpell)
End With
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True
End If
Else
MsgBox "Spell check is not available for this item."
End If
ctlSpell.SetFocus
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

Top