Hi,

I am using word.basic object to do spell check with my VB application.

I have written code to do the spell check in the Validate event. If i use the mouse to move to another control then the validate event fires twice. In case of the usage of the tab (keyboard) then this does'nt occur.


Private Sub txtTentArrsComm_Validate(Cancel As Boolean)

Const strPROCEDURE_NAME = "txtTentArrsComm_Validate"

Dim strCorrectText As String ' Holds the corrected return text

'On Error GoTo txtTentArrsComm_ValidateError

If ActiveControl.Name <> txtTentArrsComm.Name Then

Exit Sub

End If

If mblnSpellCheck(txtTentArrsComm.Text, strCorrectText) = False Then

Exit Sub

End If

txtTentArrsComm.Text = strCorrectText

End Sub






Public Function mblnSpellCheck(ByVal vstrIncorrectText As String, _
ByRef rstrCorrectText As String) As Boolean

'Created By : Sri Prabu V.C
'Date Created : 02 Mar 2000
'-------------------------------------------------------------------------------------------
'Checks the spell for the Text
'
'Input:
' vstrIncorrectText - Text which has Incorrect spell
'
'Output:
' rstrCorrectText - Text which has Correct spell
'
'Function returns true on success
'-------------------------------------------------------------------------------------------

Const strPROCEDURE_NAME = "mblnSpellCheck"

Dim objWord As Object 'Instance of the objWord Object
Dim strRetText As String 'Holds the selected Text in objWord
Dim strTextLines As String 'Holds the corrected text
Dim strNote As String 'Holds etc Error Info
Static blnCheckInstance As Boolean 'True if it is already running

On Error GoTo mblnSpellCheckError

If mstrFormMode = mstrREAD_MODE Then

rstrCorrectText = vstrIncorrectText
mblnSpellCheck = True
Exit Function

End If

If blnCheckInstance = True Then

rstrCorrectText = vstrIncorrectText
mblnSpellCheck = True
Exit Function

End If

blnCheckInstance = True

strNote = "Create an instance of the objWord object..."

'Create an instance of the objWord object
Set objWord = CreateObject("Word.Basic")

Call gSetStatus("Executing Spell Check Tool from Word...")

strNote = "Execute the Spell Check Tool..."

App.OleRequestPendingMsgTitle = "Spell Check Tool from Word"
App.OleRequestPendingMsgText = "Spell Check window is behind your Application"
App.OleRequestPendingMsgText = App.OleRequestPendingMsgText & vbNewLine & "Please finish spell checking first"

App.OleRequestPendingTimeout = 86400000 'Set the Ole request timer to one day

With objWord

.AppMinimize 'Minimise the objWord object
.AppHide 'Hide the objWord object

.FileNew 'Open a new file document
.Insert vstrIncorrectText 'Insert the Incorrect Text that is passed
'in the parameter

'Skip if any error occurs on the Spell check Tool
On Error Resume Next

.ToolsSpelling 'Run the tool to check the spelling

'Reset the Error Handler to this function Error handler
On Error GoTo mblnSpellCheckError

.EditSelectAll 'Select the all text in the document

strRetText = .Selection$() 'return the selected text

strTextLines = Left$(strRetText, Len(strRetText) - 1)

.FileClose 2 'Close the File document
.AppClose 'Close the Application

End With

'Reset to Default Value
App.OleRequestPendingTimeout = 5000
App.OleRequestPendingMsgTitle = App.Title
App.OleRequestPendingMsgText = vbNullString

strNote = "Reset the Word Object..."

'Reset the Word Object
Set objWord = Nothing

strNote = "Replace the return key with new line key..."

'Replace the return key with new line key
rstrCorrectText = Replace(strTextLines, Chr(13), vbNewLine)

Call gSetStatus(vbNullString)

DoEvents
blnCheckInstance = False
mblnSpellCheck = True
Exit Function

mblnSpellCheckError:

Call gusrErr.ShowErrInfo(mstrMODULE_NAME, strPROCEDURE_NAME, strNote)
Call gSetStatus(vbNullString)
Me.MousePointer = vbNormal
blnCheckInstance = False

End Function