Run the Spell Check through code

  • Thread starter Thread starter LisaB
  • Start date Start date
L

LisaB

Does anyone know the code like the DoCmd or DoMenuItem to run the spell
checker?

I have a client who wants me to put a command button on the user input form
to run the spell checker that will check the Memo Field
 
LisaB said:
Does anyone know the code like the DoCmd or DoMenuItem to run the
spell checker?

I have a client who wants me to put a command button on the user
input form to run the spell checker that will check the Memo Field

The command is

RunCommand acCmdSpelling

but you'll first want to set the focus to the control you want to
spell-check; e.g.,

Me!txtMyMemoField.SetFocus
RunCommand acCmdSpelling
 
Does anyone know the code like the DoCmd or DoMenuItem to run the spell
checker?

I have a client who wants me to put a command button on the user input form
to run the spell checker that will check the Memo Field

The following will activate the spellchecker (if installed - will not work with
RunTime installations):

DoCmd.RunCommand acCmdSpelling

This will check the spelling of all the fields on the form, not just the Memo
field, and will move forward through the form's recordset from the current
record until the last record has been checked (this is of no consequence if the
form is filtered to one record only). I don't think you can limit it to one
field.
 
Dirk Goldgar said:
The command is

RunCommand acCmdSpelling

but you'll first want to set the focus to the control you want to
spell-check; e.g.,

Me!txtMyMemoField.SetFocus
RunCommand acCmdSpelling

Hmm, it occurs to me after reading Bruce's response that you may have to
select the text in the memo field to restrict the check to that text:

With Me!txtMyMemoField
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
RunCommand acCmdSpelling
 
Thank You,

What if I would like to check more than the one memo field on the form, for
example if the form has 3 text fields and 2 memo fields to be spell checked,
how do I limit the spell checker code to only the current record?

one of the forms I am using this function on, pulls more than one
record from the database. This function goes through all the records even
if I highlight the text I want checked.
 
LisaB said:
Thank You,

What if I would like to check more than the one memo field on the
form, for example if the form has 3 text fields and 2 memo fields to
be spell checked, how do I limit the spell checker code to only the
current record?

one of the forms I am using this function on, pulls more than
one record from the database. This function goes through all the
records even if I highlight the text I want checked.

The code I posted *shouldn't* check more than the field it selects -- it
doesn't for me, at least. You did use the amended version, yes? If
it's going through all the fields, something I hadn't anticipated is
going on, because it works in my quick test.

To check all fields on the current record, this seems to work:

RunCommand acCmdSelectRecord
RunCommand acCmdSpelling

If you want to check multiple fields but not all of them, I think you're
going to have to do them one at a time: programmatically select a
field, RunCommand acCmdSpelling, programmatically select another field,
RunCommand acCmdSpelling ... and so on.
 
Here is a bit of sample code. It can be generalized, but this should give you
the idea. I think I've got all the necessary steps in this sample code. It's
been awhile since I've done this and I am on a computer without my sample code.

Private Sub Command30_Click()

With Me.txtOtherRace
.SetFocus
If Len(.Text & vbNullString) > 0 Then
'Must check the length, because if it is zero then the spellcheck
'and you initiate spellchecking, the spellcheck will check the entire form
'and the entire recordset
.SelStart = 0
.SelLength = Len(.Text)
DoCmd.RunCommand acCmdSpelling
End If
End With

With Me.txtOtherHealthIssue
.SetFocus
If Len(.Text & vbNullString) > 0 Then
.SelStart = 0
.SelLength = Len(.Text)
DoCmd.RunCommand acCmdSpelling
End If
End With

End Sub
 
Thanks Dirk and John for refreshing my memory on this. I just couldn't recall
how to limit the spellcheck to one field/record. <sheesh>
 
Back
Top