|
-
Apr 22nd, 2004, 01:28 PM
#1
Thread Starter
Frenzied Member
Word app spell check problem
I've got a program that reads a comment field into a datareader. As it loops through the datareader, it calls a Word app to spellcheck each comment. The comment should be displayed in a textbox when the spell check runs, but nothing shows. I realize nothing will show when there's no corrections because the loop will run too fast to see it, but when it does stop to check, the text should show.
Also, sometimes the datareader (or maybe the spell checker) truncates the comment in the middle of a word, showing a misspelling where there is none. The code's below, thanks.
VB Code:
Private Sub CheckSpell()
Dim strSql, strPath, strCn As String
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim iData As IDataObject
strSql = "SELECT DISTINCT comment FROM Main WHERE month = '" & cboMonth.SelectedItem & "'"
strPath = strRelPath & mstrFilePath
strCn = strProv & strPath
Try
objTempDoc = objWord.Documents.Add
objWord.Visible = False
' Position Word off the screen...this keeps Word invisible throughout.
objWord.WindowState = 0
objWord.Top = -3000
cn = New OleDbConnection(strCn)
cmd = New OleDbCommand(strSql, cn)
cn.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Do While dr.Read
txtSpell.Clear()
txtSpell.Text = dr("Comment")
'SpellCheck(txtSpell.Text)' Copy the contents of the textbox to the clipboard
Clipboard.SetDataObject(txtSpell.Text)
' With the temporary document, perform either a spell check or a complete
' grammar check, based on user selection.
With objTempDoc
.Content.Paste()
.Activate()
.CheckSpelling()
' After user has made changes, use the clipboard to
' transfer the contents back to the text box
.Content.Copy()
iData = Clipboard.GetDataObject
If iData.GetDataPresent(DataFormats.Text) Then
txtSpell.Text = CType(iData.GetData(DataFormats.Text), String)
End If
.Saved = True
'.Close()
End With
Loop
objTempDoc.Close()
objWord.Quit()
dr.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error Spell Checking", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|