vremo
asked on
Spell Check Rich Text Box Controls
Greetings experts, My first question ever posted to the forum...(I live by this forum..great job!!)
I've develped a MS Access (2002) app and I'm currently struggling to include spell checking specifically on a Richtext Control. I'm using Word Automation to perform the spell check but I cannot figure out how to maintain the text's RICHTEXT format..
Here is the way I've invisioned it :
User clicks spell check
program copies richtext from richtext control to clipboard
launch MS Word (hidden of course)
paste contents into Word
rull spell check
copy richtext from Word back to clipboard
paste contents from clipboard back into richtext control..
I could not for the life of me figure out how to copy richtext contents from MS Word to the clipboard then paste into my richtext control..so I'm temporarily just copying the contents w/o maintaining the format..
see code below:
Set oWord = CreateObject("Word.Applica tion")
sRTF = desc.TextRTF
lSuccess = OpenClipboard(Me.hWnd)
lRTF = RegisterClipboardFormat("R ich Text Format")
lSuccess = EmptyClipboard
hGlobal = GlobalAlloc(GMEM_MOVEABLE Or GMEM_DDESHARE, Len(sRTF))
lpString = GlobalLock(hGlobal)
CopyMemory lpString, ByVal sRTF, Len(sRTF)
GlobalUnlock hGlobal
SetClipboardData lRTF, hGlobal
CloseClipboard
GlobalFree hGlobal
oWord.Selection.Paste
oTmpDoc.CheckSpelling
MyData = oTmpDoc.Content
oTmpDoc.Close False, False, False
thanks,Vincent
Set oTmpDoc = Nothing
Word.Application.Visible = False
oWord.Quit
Set oWord = Nothing
desc.Value = ""
desc.SelRTF = MyData
End Sub
I've develped a MS Access (2002) app and I'm currently struggling to include spell checking specifically on a Richtext Control. I'm using Word Automation to perform the spell check but I cannot figure out how to maintain the text's RICHTEXT format..
Here is the way I've invisioned it :
User clicks spell check
program copies richtext from richtext control to clipboard
launch MS Word (hidden of course)
paste contents into Word
rull spell check
copy richtext from Word back to clipboard
paste contents from clipboard back into richtext control..
I could not for the life of me figure out how to copy richtext contents from MS Word to the clipboard then paste into my richtext control..so I'm temporarily just copying the contents w/o maintaining the format..
see code below:
Set oWord = CreateObject("Word.Applica
sRTF = desc.TextRTF
lSuccess = OpenClipboard(Me.hWnd)
lRTF = RegisterClipboardFormat("R
lSuccess = EmptyClipboard
hGlobal = GlobalAlloc(GMEM_MOVEABLE Or GMEM_DDESHARE, Len(sRTF))
lpString = GlobalLock(hGlobal)
CopyMemory lpString, ByVal sRTF, Len(sRTF)
GlobalUnlock hGlobal
SetClipboardData lRTF, hGlobal
CloseClipboard
GlobalFree hGlobal
oWord.Selection.Paste
oTmpDoc.CheckSpelling
MyData = oTmpDoc.Content
oTmpDoc.Close False, False, False
thanks,Vincent
Set oTmpDoc = Nothing
Word.Application.Visible = False
oWord.Quit
Set oWord = Nothing
desc.Value = ""
desc.SelRTF = MyData
End Sub
Just a thought. It may not be any easier to use that the Word speller, but doesn't Access have its own spell checker?
ASKER
Thanks GrahamSkan ! Access spelll checker does not seem to work on RichText Box controls...unless of course I am doing something incorrectly...?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again GrahamSkan ! This may absolutely work, I will give it a try and let you know... but it seems a bit clunky and cumbersome as a solution...:(.
Any other ideas ?
Ideally I'd like to have a spell check work similar to MS Word (ie underline misspelled words as you type) ...
Any other ideas ?
Ideally I'd like to have a spell check work similar to MS Word (ie underline misspelled words as you type) ...
ASKER
GrahamSkan, I tried your recommended solution and it does work though, what I see happening is that MS Word quickly launches and closes upon completion of the spell check and sometimes causes a delay in closing which of course does not appear clean to the user..any thoughts?
See the final code below:
Dim oWord As Object
Dim oTmpDoc As Object
Dim tester As String
Dim sRTF As String
Dim lSuccess As Long
Dim lRTF As Long
Dim hGlobal As Long
Dim lpString As Long
Dim hClipMemory As Long
Dim MyData As String
' Create a Word document object...
Set oWord = CreateObject("Word.Applica tion")
Set oTmpDoc = oWord.Documents.Add
Word.Application.Visible = False
sRTF = desc.TextRTF
' oTmpDoc.Visible = False
lSuccess = OpenClipboard(Me.hwnd)
lRTF = RegisterClipboardFormat("R ich Text Format")
lSuccess = EmptyClipboard
hGlobal = GlobalAlloc(GMEM_MOVEABLE Or GMEM_DDESHARE, Len(sRTF))
lpString = GlobalLock(hGlobal)
CopyMemory lpString, ByVal sRTF, Len(sRTF)
GlobalUnlock hGlobal
SetClipboardData lRTF, hGlobal
CloseClipboard
GlobalFree hGlobal
oWord.Selection.Paste
oTmpDoc.CheckSpelling
'desc.SaveAs "C:\oTmpDoc.Doc", wdFormatRTF
oTmpDoc.SaveAs "C:\Documents and Settings\oTmpDoc.Doc", wdFormatRTF
oTmpDoc.Close False, False, False
Set oTmpDoc = Nothing
Me.desc.LoadFile "C:\Documents and Settings\oTmpDoc.Doc"
oWord.Quit
See the final code below:
Dim oWord As Object
Dim oTmpDoc As Object
Dim tester As String
Dim sRTF As String
Dim lSuccess As Long
Dim lRTF As Long
Dim hGlobal As Long
Dim lpString As Long
Dim hClipMemory As Long
Dim MyData As String
' Create a Word document object...
Set oWord = CreateObject("Word.Applica
Set oTmpDoc = oWord.Documents.Add
Word.Application.Visible = False
sRTF = desc.TextRTF
' oTmpDoc.Visible = False
lSuccess = OpenClipboard(Me.hwnd)
lRTF = RegisterClipboardFormat("R
lSuccess = EmptyClipboard
hGlobal = GlobalAlloc(GMEM_MOVEABLE Or GMEM_DDESHARE, Len(sRTF))
lpString = GlobalLock(hGlobal)
CopyMemory lpString, ByVal sRTF, Len(sRTF)
GlobalUnlock hGlobal
SetClipboardData lRTF, hGlobal
CloseClipboard
GlobalFree hGlobal
oWord.Selection.Paste
oTmpDoc.CheckSpelling
'desc.SaveAs "C:\oTmpDoc.Doc", wdFormatRTF
oTmpDoc.SaveAs "C:\Documents and Settings\oTmpDoc.Doc", wdFormatRTF
oTmpDoc.Close False, False, False
Set oTmpDoc = Nothing
Me.desc.LoadFile "C:\Documents and Settings\oTmpDoc.Doc"
oWord.Quit