Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I use the spell checker in Access with code.

Status
Not open for further replies.

AvatarZA

Programmer
Sep 26, 2002
42
0
0
ZA
I need to use the spell checker that access has built in to check the spelling in a database how can I do this in VB6 any help would be appreciated.
 
Dim strText As String
Dim lngSuggWord As Long
Dim lngStart As Long
Dim lngPos As Long
Dim blnDone As Boolean
Dim objWord As Word.Application
Dim objDoc As Document
Dim colSuggestions As SpellingSuggestions
Dim colSpellErrors As ProofreadingErrors
'
'---------------------------------------------
' Spell check the text.
'---------------------------------------------
'
On Error GoTo ErrorHandler
'
' Start and hide Word.
'
Set objWord = CreateObject("word.application")
objWord.Visible = False
objWord.WindowState = wdWindowStateMinimize
'
' Create a new Word document.
'
Set objDoc = objWord.Documents.Add
'
' Loop through the text.
'
blnDone = False
lngStart = 1
lngPos = 0

Do While Not blnDone
'
' Parse the text into words.
'
lngStart = lngPos + 1
lngPos = InStr(lngStart, txtText.Text, " ")
If lngPos = 0 Then
lngPos = Len(txtText.Text) + 1
blnDone = True
End If
'
' Select a word.
'
txtText.SelStart = lngStart - 1
txtText.SelLength = lngPos - lngStart

If txtText.SelText <> &quot;&quot; Then
'
' Set the Word document's range to
' the selected text and call the
' spell checker.
'
objDoc.Range.Delete
objDoc.Range = txtText.SelText
Set colSpellErrors = objDoc.SpellingErrors
'
' If we have errors, get the suggestions.
'
If colSpellErrors.Count > 0 Then
With frmSpellCheck
.txtBadWord.Text = colSpellErrors.Item(1)

Set colSuggestions = objWord.GetSpellingSuggestions(colSpellErrors.Item(1))
.lstSuggestions.Clear

For lngSuggWord = 1 To colSuggestions.Count
.lstSuggestions.AddItem colSuggestions.Item(lngSuggWord)
Next
'
' Show the suggested word dialog.
'
.Show vbModal
'
' Swap the text taking into account the
' new word's length may differ.
'
If .ReplacementWord <> &quot;&quot; Then
txtText.SelText = .ReplacementWord
lngPos = lngPos + .LengthDifference
End If
End With
End If
End If
Loop

txtText.SelStart = 0
txtText.SelLength = 0

GoTo NormalExit


ErrorHandler:
MsgBox &quot;The following error occured during the document's spelling&quot; & vbCrLf & Err.Description

NormalExit:
'
' Close word and clean up.
'
objDoc.Close savechanges:=wdDoNotSaveChanges
objWord.Quit savechanges:=wdDoNotSaveChanges
Set objWord = Nothing
Set objDoc = Nothing
 
Thanks for the help...

But I need to perform the spell check on a Access database or a Table.

Thanks for the word spell check.
 
Thanks for the help I try and use the second option.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top