Click to See Complete Forum and Search --> : error using Word object for spell checking


catgirl78
March 21st, 2001, 07:40 PM
i have a form with a text box and a list box. when the user type in the text box, a list of word suggestion would display in the list box. I had set the reference to word object but errors still occur. the codes i used are as below:

the error i received when i started typing in the textbox is "object variable or with block varilable not set"

'name of listbox = lstCorrect
'name of textbox =txt_ResFree

in the module.bas:
Public SC As Word.Application
Public Doc As Document
Public SpellErrors As SpellingSuggestions
Public SpellError As SpellingSuggestion

Public Sub Main()
Set SC = New Word.Application
SC.Visible = False
Set Doc = SC.Documents.Open(AppPath& "Blank.doc")
frmSpell.Show
End Sub
Public Function AppPath() As String
Dim sAns As String
sAns = App.Path
If Right(App.Path, 1) <> "\" Then sAns = sAns & "\"
AppPath = sAns
End Function

in the form:

Private Sub txt_ResFree_Change()
lstCorrect.Visible = True
lstCorrect.Clear
Set SpellErrors = SC.GetSpellingSuggestions(Word:=txt_ResFree.Text)
If SpellErrors.Count > 0 Then
For Each SpellError In SpellErrors
lstCorrect.AddItem SpellError.Name
Next SpellError
ElseIf SC.CheckSpelling(Word:=txt_ResFree.Text) Then
lstCorrect.AddItem txt_ResFree.Text
End If
End Sub

Private Sub lstCorrect_DblClick()
Dim sel As Integer
Clipboard.Clear
Clipboard.SetText lstCorrect.Text
txt_ResFree.Text = lstCorrect.Text
End Sub

Please HELP!!..

thanks

GungaDin
March 21st, 2001, 10:16 PM
Is your project set up to use Sub Main as the Startup Object?

To check this go to the Project Menu -> Project Properties

Go to the General tab and check the Startup Object. If it is set to frmSpell, you will need to change it to Sub Main, otherwise you won't be starting word and you will get the error you stated.

Hope this helps,

Nathan.

PS I don't think you need to open the blank document to get the spell checker to work.