spell checker cycles thru all records behind a form

G

Guest

Hello,

Just found on my forms that have record controls at the bottom that when I
spell check a text box field the spell checker will cycle thru the text box
on all records not just the current one. This is not good as the end user if
not paying attention will end up on a totally different record than they were
working on. Of course this can lead to all kinds of data entry errors.

Wondering if any way to limit spell checker to current record only?

Thanks much!
Doug
 
G

Guest

I've tried to get the F7 key to work properly in my app without success. I've
also tried to add code in the afterupdate event of the textbox and get
errors. Here is what I finally got to work.

I added an option button beside each text box and labeled it Spell Check.
Here is the VBA. Put the Function in a Module.

Hope this helps.

Code behind Option Button

Private Sub Option128_Click()
'Comments is the name of the Textbox that needs spellchecking
Dim ctl As Control
Set ctl = Me.Comments
Me.Comments.SetFocus
Call CheckSpelling(ctl)
End Sub


Function in new Module

Public Function CheckSpelling(t As TextBox)
On Error GoTo Err_Handler

Dim objWord As Object
Dim objDoc As Object
Dim strResult As String

'Create a new instance of word Application
If (Len(t.Text) = 0) Then
'nahhhhhhhhhhh
Else
Set objWord = CreateObject("word.Application")
objWord.Visible = False

Select Case objWord.Version
'Office 2000, xp, 2k3
Case "9.0", "10.0", "11.0"
Set objDoc = objWord.Documents.Add(, , 1, True)
'Office 97
Case Else
Set objDoc = objWord.Documents.Add
End Select

objDoc.Content = t.Text
objDoc.CheckGrammar
objWord.Visible = False

strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
'correct the carriage returns
strResult = Replace(strResult, Chr(13), Chr(13) & Chr(10))

If t.Text = strResult Then
' There were no spelling errors, so give the user a
' visual signal that something happened
MsgBox "The spelling check is complete.", vbInformation +
vbOKOnly, "Spelling Complete"
End If
'Clean up
objDoc.Close False
Set objDoc = Nothing
objWord.Visible = False
objWord.Application.Quit True
Set objWord = Nothing

' Replace the selected text with the corrected text. It's important
that
' this be done after the "Clean Up" because otherwise there are
problems
' with the screen not repainting
t.Text = strResult
End If
Done:
Exit Function

Err_Handler:

Resume Done

End Function
 

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