Form SpellChecker and GrammarChecker

B

Bart Workman

I have created a form that allows my user to type in a
text box and run a spell-check and grammar check using
WORD. My problem is that it opens a word document after
running the spell-check and grammar check. I would really
like it to not open the word document at all but I have
been unsuccessful in getting it to programmatically close
the word document. I would appreciate any advice.

'The following code runs a spell check and grammar check

Private Sub cmdSpellCheck_Click()

Dim oWDBasic As Object
Dim sTmpString As String

Set oWDBasic = CreateObject("Word.Basic")
oWDBasic.FileNew
txtFreeForm.SetFocus
oWDBasic.Insert txtFreeForm.Text
On Error Resume Next
oWDBasic.ToolsSpelling
oWDBasic.ToolsGrammar
oWDBasic.EditSelectAll
oWDBasic.SetDocumentVar "MyVar", WDBasic.Selection
sTmpString = oWDBasic.GetDocumentVar("MyVar")
'The following code will NOT close WORD
'DoCmd.Close acModule, "word.basic", acSaveNo
'DoCmd.Close , "word.basic", acSaveNo
'DoCmd.Close , oWDBasic, acSaveNo
'oWDBasic.Quit
txtFreeForm.Text = Left(sTmpString,Len(sTmpString) - 1)
MsgBox "The spell check and grammar check are complete"

End Sub

Private Sub cmdOk_Click()

txtFreeForm.SetFocus
gstrFreeForm = txtFreeForm.Text
If IsNull(txtFreeForm) Then
MsgBox "You must type something in the text box"
Else
DoCmd.Close
End If

End Sub
 
T

TC

Gak! None of the Access DoCmd or Close methods will ever close a program
that you have started via automation (like here). You need to use the
appropriate method of the program in question, then release the reference
that you had to that program.

I note that you are using Word Basic. Word Basic can still be used in Word
97 (and higher?), but it has been replaced by Word VBA. This is how you
would do it in Word VBA. You'll have to find the equivalent command in Word
Basic - apparently it is not Quit - or convert your code to use Word VBA.

dim oWord as object
set oWord = createobject ("Word.Application") ' <<< use Word VBA.
[do things]
oWord.Quit ' <<< ' wdDoNotSaveChanges
set oWord = nothing ' <<<

I can't remember the value of wdDoNotSaveChanges (and I do not have Word
here to check). If you change to use Word VBA, and you need the value of
that constant, just open Word, press Alt-F11 to go to the code editor, press
ctrl-g to open the debug window, then type:

? wddonotsavechanges

HTH,
TC
 

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

Similar Threads


Top