• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

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.Application")
    sRTF = desc.TextRTF
   
     lSuccess = OpenClipboard(Me.hWnd)
     lRTF = RegisterClipboardFormat("Rich 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

0
vremo
Asked:
vremo
  • 3
  • 2
1 Solution
 
GrahamSkanRetiredCommented:
Just a thought. It may not be any easier to use that the Word speller, but doesn't Access have its own spell checker?
0
 
vremoAuthor Commented:
Thanks GrahamSkan ! Access spelll checker does not seem to work on RichText Box controls...unless of course I am doing something incorrectly...?

0
 
GrahamSkanRetiredCommented:
I'm afraid that I've been forced to cheat.
There doesn't seem to be a simple way to programatically paste to a Rich Text Box.

This code simply saves the Word document and reads it in to the RTB.

Private Sub Command1_Click()
    'sRTF represents the rich text formatted string to paste into Word
    Dim sRTF As String
    Dim strData As String
   
    'Copy the contents of the Rich Text to the clipboard
    Dim lSuccess As Long
    Dim lRTF As Long
    Dim hGlobal As Long
    Dim lpString As Long
    Dim oWord As Word.Application
    Dim oTmpDoc As Word.Document
   
    sRTF = Me.Desc.SelRTF
    Set oWord = CreateObject("Word.Application")
    oWord.Visible = True
    sRTF = Me.Desc.TextRTF
   
    lSuccess = OpenClipboard(Me.hwnd)
    lRTF = RegisterClipboardFormat("Rich 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
    Set oTmpDoc = oWord.Documents.Add
    oWord.Selection.Paste
   
    oTmpDoc.CheckSpelling
    oTmpDoc.SaveAs "C:\oTmpDoc.Doc", wdFormatRTF
    oTmpDoc.Close False, False, False
    Set oTmpDoc = Nothing
    Me.Desc.LoadFile "C:\oTmpDoc.Doc"
    Word.Application.Visible = False
    oWord.Quit
    Set oWord = Nothing
End Sub

0
 
vremoAuthor Commented:
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) ...

0
 
vremoAuthor Commented:
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.Application")
    Set oTmpDoc = oWord.Documents.Add
    Word.Application.Visible = False
    sRTF = desc.TextRTF
'     oTmpDoc.Visible = False
     lSuccess = OpenClipboard(Me.hwnd)
     lRTF = RegisterClipboardFormat("Rich 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

0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now