magicmandan
Programmer
- Mar 9, 2010
- 13
Hi,
I have an extremely frustrating problem. I have developed an Access database (Office 2007 on Windows 7).
I want to allow users to spell and grammar check certain information that they enter onto the system.
As Access has no native grammar checker I found and adapted the following code that uses the Microsoft Word Grammar and spelling dialog which is perfect for my user needs.
The function is as follows:
Public Function SpellIt(ckStr As String, boxChecked As String) As String
On Error GoTo SpellIt_Err
Dim oldStr As String
Dim objWord As Word.Application
Dim doc As Word.Document
Dim uCancel As Boolean
Dim bChecked As String
bChecked = boxChecked
oldStr = ckStr
Set objWord = CreateObject("Word.Application")
With objWord
.visible = False
Set doc = .Documents.Add
.Selection.Text = ckStr
.visible = True
.Activate
.visible = False
.Dialogs(wdDialogToolsSpellingAndGrammar).Show
If Len(.Selection.Text) <> 1 Then
ckStr = .Selection.Text
uCancel = False
Else
'ckStr = oldStr
uCancel = True
End If
' close the document
doc.Close wdDoNotSaveChanges
Set doc = Nothing
' close the Word instance
.Quit wdDoNotSaveChanges
End With
'objWord.Quit wdDoNotSaveChanges
Set objWord = Nothing
If uCancel = True Then
SpellIt = oldStr
Dialog.Box "You cancelled the spell checker for " & UCase(bChecked) & ", please make sure you manually check the spelling and grammar for this entry before saving the record.", , "::Spellcheck Cancelled::", , , 0
Exit Function
End If
SpellIt = Replace(ckStr, Chr(13), Chr(13) & Chr(10))
Dialog.Box "Spelling and Grammar Check Complete for text contained in '" & UCase(bChecked) & "'.", vbInformation, ":Spelling And Grammar Completed:", , , 0
Exit Function
SpellIt_Err:
Err.Clear
Dialog.Box "There was an error performing the grammar and spelling check for the text in " & UCase(bChecked) & ".\n" & _
"As a precaution, any changes made within the grammar and spelling dialog box have not been retained please correct any mistakes manually.", _
vbCritical, "Error Message Box: Spelling and Grammar Check NOT Complete:", , , 0
SpellIt = oldStr
End Function
===================================
This is called by clicking a button on a modal pop-up form as shown below:
Private Sub cmdSP_Click()
If IsNull(Me.txtNotes) Or Me.txtNotes = "" Then
Else
Me.txtNotes = SpellIt(Me.txtNotes, "Notes")
End If
End Sub
====================================
While developing this solution at home it worked perfectly on my Windows XP PC, however when i tried the database onsite users reported that the application would hang whenever the spellcheck button was clicked.
I have discovered that access is not hanging but is in fact waiting for the user to interact with the word spelling and grammar dialog box which is hidden under the access database window. If i open task manager i see an entry for the spelling and grammar dialog in the applications tab - and if clicked it will then float above the open access form as it should in the first place.
The most frustrating part of this problem is that today while on site i experimented with the spellit function by changing the order of .activate and .visible = true/false and reached the point where the above code word properly - OH JOY!!
But alas no!
Having thought I'd solved the problem I re-secured the database (locked code from viewing, re-setup my custom ribbon, etc) and then started the application again and tried to use the spell check functionality - the same issue occured - the dialog box was hiding in the background.
However if i then open the calling form in design mode, close it and then reopen it, the spelling dialog is shown as it should be!!!
I am so lost with this behaviour can anyone please suggest a solution.
Thanks.
I have an extremely frustrating problem. I have developed an Access database (Office 2007 on Windows 7).
I want to allow users to spell and grammar check certain information that they enter onto the system.
As Access has no native grammar checker I found and adapted the following code that uses the Microsoft Word Grammar and spelling dialog which is perfect for my user needs.
The function is as follows:
Public Function SpellIt(ckStr As String, boxChecked As String) As String
On Error GoTo SpellIt_Err
Dim oldStr As String
Dim objWord As Word.Application
Dim doc As Word.Document
Dim uCancel As Boolean
Dim bChecked As String
bChecked = boxChecked
oldStr = ckStr
Set objWord = CreateObject("Word.Application")
With objWord
.visible = False
Set doc = .Documents.Add
.Selection.Text = ckStr
.visible = True
.Activate
.visible = False
.Dialogs(wdDialogToolsSpellingAndGrammar).Show
If Len(.Selection.Text) <> 1 Then
ckStr = .Selection.Text
uCancel = False
Else
'ckStr = oldStr
uCancel = True
End If
' close the document
doc.Close wdDoNotSaveChanges
Set doc = Nothing
' close the Word instance
.Quit wdDoNotSaveChanges
End With
'objWord.Quit wdDoNotSaveChanges
Set objWord = Nothing
If uCancel = True Then
SpellIt = oldStr
Dialog.Box "You cancelled the spell checker for " & UCase(bChecked) & ", please make sure you manually check the spelling and grammar for this entry before saving the record.", , "::Spellcheck Cancelled::", , , 0
Exit Function
End If
SpellIt = Replace(ckStr, Chr(13), Chr(13) & Chr(10))
Dialog.Box "Spelling and Grammar Check Complete for text contained in '" & UCase(bChecked) & "'.", vbInformation, ":Spelling And Grammar Completed:", , , 0
Exit Function
SpellIt_Err:
Err.Clear
Dialog.Box "There was an error performing the grammar and spelling check for the text in " & UCase(bChecked) & ".\n" & _
"As a precaution, any changes made within the grammar and spelling dialog box have not been retained please correct any mistakes manually.", _
vbCritical, "Error Message Box: Spelling and Grammar Check NOT Complete:", , , 0
SpellIt = oldStr
End Function
===================================
This is called by clicking a button on a modal pop-up form as shown below:
Private Sub cmdSP_Click()
If IsNull(Me.txtNotes) Or Me.txtNotes = "" Then
Else
Me.txtNotes = SpellIt(Me.txtNotes, "Notes")
End If
End Sub
====================================
While developing this solution at home it worked perfectly on my Windows XP PC, however when i tried the database onsite users reported that the application would hang whenever the spellcheck button was clicked.
I have discovered that access is not hanging but is in fact waiting for the user to interact with the word spelling and grammar dialog box which is hidden under the access database window. If i open task manager i see an entry for the spelling and grammar dialog in the applications tab - and if clicked it will then float above the open access form as it should in the first place.
The most frustrating part of this problem is that today while on site i experimented with the spellit function by changing the order of .activate and .visible = true/false and reached the point where the above code word properly - OH JOY!!
But alas no!
Having thought I'd solved the problem I re-secured the database (locked code from viewing, re-setup my custom ribbon, etc) and then started the application again and tried to use the spell check functionality - the same issue occured - the dialog box was hiding in the background.
However if i then open the calling form in design mode, close it and then reopen it, the spelling dialog is shown as it should be!!!
I am so lost with this behaviour can anyone please suggest a solution.
Thanks.