Spellcheck a field

R

RitchieJHicks

I added some code so that, on event end, the spell check was automatically
launched to check the text inpuuted in to the memo box. However, this
resulted in a bad loop where I kept getting confirmation that the spell check
was complete over and over again.

What is the recommended way to spell check a field? And what would the code
look like please?

Regards,
Ritchie.
 
A

Arvin Meyer [MVP]

Put the code below in a standard module. Put a button on your form and set
its Click event property to:

=Spell()

It will check every textbox on your form.

Public Function Spell()
' Arvin Meyer 9/17/1998
' Adapted from code by Terry Wickenden
Dim ctlSpell As Control
Dim frm As Form
Set frm = Screen.ActiveForm
DoCmd.SetWarnings False
' Enumerate Controls collection.
For Each ctlSpell In frm.Controls
If TypeOf ctlSpell Is TextBox Then
If Len(ctlSpell) > 0 Then
With ctlSpell
.SetFocus
.SelStart = 0
.SelLength = Len(ctlSpell)
End With
DoCmd.RunCommand acCmdSpelling
End If
End If
Next
DoCmd.SetWarnings True
End Function
 
D

dsc2bjn

Arvin,
This works well for what was requested; however, I have a slightly
different situation.

I only wish to spell check a single text box on the form.

I am looking for a way have automatically check the spelling of a single
text box either through a button or automatically AfterUpdate.

Any suggestions would be greatly appreciated.
 
M

Marshall Barton

Then remove the loop in Arvin's code.

Essentially, it boils down to just:

With ctlSpell
If Len(.Value) > 0 Then
.SelStart = 0
.SelLength = Len(.Value)
DoCmd.RunCommand acCmdSpelling
End If
End With
 
L

Linq Adams via AccessMonster.com

Me.YourMemoField.SetFocus

With Me!YourMemoField

If Len(.Value) > 0 Then
DoCmd.SetWarnings False
.SelStart = 1
.SelLength = Len(.Value)
DoCmd.RunCommand acCmdSpelling
.SelLength = 0
DoCmd.SetWarnings True
End If

End With

End Sub

If you place the code in the AfterUpdate event of the memo field, delete the

Me.YourMemoField.SetFocus

line.
 
D

dsc2bjn

Thanks.

I found another method which works; however, any thing typed in all caps
automatically is considerd ok.

Do you know if this code has the same issue?
 
L

Linq Adams via AccessMonster.com

I suspect that's a function of the spellchecker rather than any given code to
run the spellchecker, so it's going to be a problem, however you code it.
Sorry, I don't have time to play with this right now, but at a guess, if your
text is all in caps, do something like:

Me.MemoField = LCase(Me.MemoField)

'Place all your code to run the spellcheck here


Me.MemoField = UCase(Me.MemoField)
 
D

dsc2bjn

After I did a little more digging, I found out that it is an "Option" within
each of the Microsoft Office products. You can set a check box to either
check words in all caps or to ignore them. I guess they figure people
sometimes will be using a lot of acronyms and wish to bypass them all
together.

It is on the "Options>Spell Check" tab.

Thanks for the reply.
 

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