473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

VBA to run custom spell checker and log errors in table?

Greetings all.

I've stolen/used this code as a spell checker on forms.

Expand|Select|Wrap|Line Numbers
  1. Dim strSpell
  2.  
  3.     strSpell = myField.Value
  4.     If IsNull(Len(strSpell)) Or Len(strSpell) = 0 Then
  5.        Exit Sub
  6.     End If
  7.     With myField
  8.         .SetFocus
  9.         .SelStart = 0
  10.         .SelLength = Len(strSpell)
  11.     End With
  12.     DoCmd.SetWarnings False
  13.     DoCmd.RunCommand acCmdSpelling
  14.     DoCmd.SetWarnings True
  15.  
What I want to do is:

-loop through specific fields in a recordset
-log every spelling error (and its associated field) in a table
-display the results in a form
-return a count of the errors found

need help with the bold part.

I did a little reading, but it looks like all DoCmd.RunCommand acCmdSpelling does is launch the equivalent of a the spell checker--which, I don't believe, I can manipulate/capture.

So, how does the spell checker work? I imagine one could write code to capture a string of consecutive characters (i.e. a space before and after) and check that string against some sort of MS Office dictionary.

Any ideas how to do that?
Oct 15 '13 #1
5 5431
ADezii
8,834 Expert 8TB
Just subscribing, will return later with a possible solution...
Oct 15 '13 #2
zmbd
5,501 Expert Mod 4TB
tetsuo2030:
- Capturing the spellcheck statistics
I haven’t seen a direct method within VBA for doing this; however, at controlled-use-access-spell-check-possible:Post#5 that has a function where in the built in speller is called. Looks like there will need to be some tweaking… so that the code becomes:
Expand|Select|Wrap|Line Numbers
  1.  Public Function SpellChecker(Calling As Form)
  2.     Dim ctlSpell As Control
  3.     Dim Incoming As String, Outgoing As String
  4.     Dim line1 As Variant
  5.     'Dim mbResult As Long
  6.     DoCmd.SetWarnings False
  7.     Set ctlSpell = Calling.ActiveControl
  8.     If (ctlSpell.Locked) Then
  9.         line1 = "Cannot spell check. Field is read-only"
  10.         SpellChecker = MsgBox(line1, vbOKOnly)
  11.     Else
  12.         If Len(ctlSpell) > 0 Then
  13.             Incoming = ctlSpell
  14.             With ctlSpell
  15.                 .SetFocus
  16.                 .SelStart = 0
  17.                 .SelLength = Len(ctlSpell)
  18.             End With
  19.             DoCmd.RunCommand acCmdSpelling
  20.             Outgoing = ctlSpell
  21.         End If
  22.         ' See if any changes were made 09/29/04
  23.         If (Incoming <> Outgoing) Then
  24.             ' Notify user that changes
  25.             ' were made, if you want to,
  26.             ' or give Bronx cheer
  27.         End If
  28.     End If
  29. End Function 
You could then use the logic at line 23 to collect your stats

Call it from your control as described in the post by using something like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtexample_LostFocus()
  2.     SpellChecker Me
  3. End Sub
I'm sure that you can modify it from here to start looping thru the forms collection as an outer loop and then call and loop thru the controls collection on each form.


Otherwise:
To create a custom spell checker would be quite outside of the realm of what we can do to help; however, we can provide specific help with your code should you run into an issue during development.
The basics, of course, would be that you would need some sort of source to compare with the user entries, and then you may need to consider rather you want a literal match or maybe do approximate matching; there are two articles here on Bytes.com that cover two such methods:
ngram aproximate string matching
levenshtein approximate string matching
Then be prepared for a slow time going.

On Allen Brownes site (http://allenbrowne.com/links.html) there is a link to an open source spell checker: http://www.pcesoft.com/Access-Spell-...urce-Code.html that you can incorporate into your application. However, I don't think you can capture the statistics with it.

(I see that ADezii has taken an interest and does some of the most interesting coding!)
Oct 15 '13 #3
ADezii
8,834 Expert 8TB
The concept is to:
  1. Create a Recordset and Loop thru each Field in every Record.
  2. Pass the Value in each Field along with the Field Name to a Public Function.
  3. This Public Function will use Automation Code using (Microsoft Word), and invoke Word's Spell Checker to check each Value for misspelling.
  4. If a misspelling is found, write the Field Name and the misspelled Value to a Results Table.
  5. Keep a Running Count of the number of misspellings and output that in some manner.
  6. Set the Record Source of a Form to the Results Table for viewing.
  7. This is the concept, the implementation of this concept is much more difficult, but I'll see what I can come up with.
Oct 16 '13 #4
ADezii
8,834 Expert 8TB
I have actually arrived at a rather simple solution using some Excel Automation Code and it's Spell Checking capability. I will post it in its entirety sometime tomorrow. Interesting challenge!
Oct 16 '13 #5
ADezii
8,834 Expert 8TB
As stated yesterday, I have created a solution that appears to work quite well, but hold on to your seat:
  1. The entire Logic is build around a Table named Table1 with two Fields named Field1 and Field2 but should work equally well with any Table containing any number of Fields and any amount of Records.
    Expand|Select|Wrap|Line Numbers
    1. 'Table1 definition
    2. Field1    Field2
    3. Alpha     Marrch
    4. Tangoo    April
    5. Charlie   May
    6. Foxxtrot  June
    7. Braavo    Jully
    8. Zuluu     August
    9. Dellta    September
    10. Lima      Novemberr
    11.  
  2. Create an exact Copy of Table1 (structure only) and name it tblResults. This Table will contain the Field Names along with the misspellings.
  3. Copy-N-Paste the following to a Standard Code Module in order to create a Global 'Instance' of Microsoft Excel.
    Expand|Select|Wrap|Line Numbers
    1. 'Create a 'Global' Instance of Microsoft Excel in order to use
    2. 'its Spell Checking capabilities.
    3. Public appExcel As New Excel.Application
  4. Copy-N-Paste the following Function Definition to a Standard Code Module. This Function will verify each Field Value in every Record to see if it is spelled correctly.
    Expand|Select|Wrap|Line Numbers
    1. Public Function fSpellCheck2(strFieldName As String, strStringToCheck As String) As String
    2. 'This Function will accept every Field value in every Record and analyze the Field
    3. 'Values to see if there is a misspelling. If the Value represented by strStringToCheck
    4. 'is misspelled (CheckSpelling(<strStringToCheck>)=False), write the Field Name as well
    5. 'as the misspelled Value to a Table (tblResults).
    6. If Not appExcel.CheckSpelling(strStringToCheck) Then
    7.   CurrentDb.Execute "INSERT INTO tblResults ([Field1],[Field2]) VALUES ('" & _
    8.                     strFieldName & "', '" & strStringToCheck & "')", dbFailOnError
    9. End If
    10. End Function
    Copy-N-Paste the Primary Code to any place where it can be executed. This Code will process the Recordset and pass the appropriate Arguments to fSpellCheck2().
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Command21_Click()
    2. On Error GoTo Err_Command21_Click
    3. Dim MyDB As Database
    4. Dim rst As DAO.Recordset
    5. Dim intNumOfFields As Integer
    6. Dim intFldCtr As Integer
    7.  
    8. Set MyDB = CurrentDb()
    9. Set rst = MyDB.OpenRecordset("Table1", dbOpenForwardOnly)
    10.  
    11. 'Clear the Results Table by DELETING all existing Records
    12. CurrentDb.Execute "DELETE * FROM tblResults", dbFailOnError
    13.  
    14. intNumOfFields = rst.Fields.Count
    15.  
    16. With rst
    17.   'Process every single Field in every Record and pass the Field
    18.   'Name as well as the actual Value to fSpellCheck2() for analysis
    19.   Do While Not .EOF
    20.     For intFldCtr = 0 To .Fields.Count - 1
    21.        Call fSpellCheck2(.Fields(intFldCtr).Name, ![Field1])
    22.         .MoveNext
    23.     Next
    24.   Loop
    25. End With
    26.  
    27. 'The number of Errors (misspellings) will actually be the number
    28. 'of Records contained within the Results Table (tblResults)
    29. MsgBox "Number of Spelling Errors: " & DCount("*", "tblResults")
    30.  
    31. 'Don't forget to clean up the mess you created, especially with the
    32. 'Global Object represented by appExcel
    33. rst.Close
    34. Set rst = Nothing
    35.  
    36. appExcel.Quit
    37. Set appExcel = Nothing
    38. '************************* End of Clean Up ************************
    39.  
    40. Exit_Command21_Click:
    41.   Exit Sub
    42.  
    43. Err_Command21_Click:
    44.   MsgBox Err.Description, vbExclamation, "Error in Command21_Click()"
    45.     Resume Exit_Command21_Click
    46. End Sub
  5. The results are contained in tblResults and here they are.
    Expand|Select|Wrap|Line Numbers
    1. Field1    Field2
    2. Field2    Tangoo
    3. Field2    Foxxtrot
    4. Field1    Braavo
    5. Field2    Zuluu
    6. Field1    Dellta
  6. Create a Form and set its Record Source to tblResults to actually view the Results.
  7. The Code is well commented, but should you have any questions, please feel free to ask.
Oct 16 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Hank Reed | last post by:
I am trying to use the spell checker on an unbound control in Access 2000. I run the checker in the AfterUpdate event of the control. After the spell checker is done, I get the following message:...
3
by: Jason L James | last post by:
Dear all, I have an app that captures text entry from the user and stores it in an SQL DB. I want to make sure that the text is spelt correctly using a spell checked; possibly the one...
8
by: Joe | last post by:
Hello All: Does anyone know of a spell checker that works with .NET? Any options will be welcome. TIA, -- Joe
4
by: sweetguy1only | last post by:
Hi all, I am a MS Access developer using VB 6 (yes, I know it is a bit old). The problem I am having is, I have a software that allows my customers to put in the information of their clients....
6
by: Neil | last post by:
Is there way to have control over the MS-Access spell checking (besides just launching it)? We want to tell it to check all records, but skip certain fields (or, alternatively, ONLY check certain...
6
by: Don | last post by:
I am looking for a C/C++ code spell checker, a tool that checks for spelling errors in C++ source code. Linux/Unix platforms. Prefer command line tool. Open source preferred, but will consider...
9
by: ARC | last post by:
Hello all, I developed a tool a year or so ago for adding your own spell-checker to an access application. This is mainly for those using the runtime, as you can't distribute the spell-checker...
3
by: Mike | last post by:
I have an app running at a client where, when the spell checker is supposed to run, it reports "Can't start spell checker because it is not installed". I have never had this before - it works...
1
by: farhin | last post by:
Hi there, i m developing an application with richtextbox control and asp spell checker control in it.the prblm faced is that Spell check is happening but the change of wrong spelling is not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.