Spell checking a text box on a form (1 Viewer)

the-m0th

Registered User.
Local time
Today, 02:53
Joined
Apr 14, 2015
Messages
51
Hi everyone,

I'm trying to get a spell check to work on a text box on a form. i've got it popping the spell check window after the box has been updated but i'd prefer it to just highlight the errors in red, rather than pop the spell check box. another problem i'm having is when it's finished spell checking the box it moves the form back to the first record. this is the code i'm using.

Code:
Private Sub txt_notes_AfterUpdate()
    If Len(Me!txt_notes & "") > 0 Then
        DoCmd.SetWarnings False
        DoCmd.RunCommand acCmdSpelling
        DoCmd.SetWarnings True
    Else
        Exit Sub
    End If
End Sub

any light you guys can shed would be much appreciated.
Wayne
 

CJ_London

Super Moderator
Staff member
Local time
Today, 02:53
Joined
Feb 19, 2013
Messages
16,773
as you have it written, spellchecker is checking the entire form, not just tthe one textbox. You may not have noticed, but just so you are aware.

To spellcheck a single control use something like

Code:
 Private Sub txt_notes_LostFocus()

  
 If Not IsNull(txt_notes) Then
    With txt_notes
        .SetFocus
        .SelStart = 0
        .SelLength = Len(txt_notes)
    End With
    DoCmd.SetWarnings False
    RunCommand acCmdSpelling
    DoCmd.SetWarnings True
End If
 
End Sub
note the event - LostFocus

with regards just highlighting words and not invoking the spellchecker window, so far as I am aware this is not possible.

You would have to write your own coding to do this, though I've no idea if it is actually possible - you would need to find a way of opening the windows language dictionary (not sure what it is called), compare word by word and then have some code to select the wrongly spelt word (you would use selstart, sellength to do this) - but that has it's own problems in that (so far as I am aware) the colour of the highlight is with system settings - so not necessarily able to change to yellow.

Then presumably you would need additional code to update the dictionary if the word is a new word and some way of triggering this update (perhaps a shortcut menu?)
 

the-m0th

Registered User.
Local time
Today, 02:53
Joined
Apr 14, 2015
Messages
51
hi,

cheers for the help. i've tried the code you posted and it works, but it does the same as the first code and changes record after it's complete. i need it to just check the spelling of the record that's currently loaded on the form.

cheers
Wayne
 

CJ_London

Super Moderator
Staff member
Local time
Today, 02:53
Joined
Feb 19, 2013
Messages
16,773
i need it to just check the spelling of the record
As I said, using the spell checker only works on a 'completed' record - you could try using the change event instead but my guess is if it works on the control.text property (which I doubt but is the one you need before you lose focus) the user will be getting lots of 'prompts' as a word is being completed - and it still won't work 'in line' as you require - you will need to write your own code, but I have no idea how you would do this
 

CJ_London

Super Moderator
Staff member
Local time
Today, 02:53
Joined
Feb 19, 2013
Messages
16,773
I found this link which may help you. Would need significant reworking (since it works on checking entire tables rather than a control) , but the principle is that it uses the excel spellchecker

http://bytes.com/topic/access/answers/952205-vba-run-custom-spell-checker-log-errors-table

looks like you need to create an error log, then compare the words in your control with the words in the error log to highlight the misspellings

good luck with your project
 

the-m0th

Registered User.
Local time
Today, 02:53
Joined
Apr 14, 2015
Messages
51
thanks a lot for that. i'm going to shelve this idea until i get a little better at this access malarkey :) there's loads of little jobs for me to be doing here and this one looks like i may be a little out of my depth.
 

vbaInet

AWF VIP
Local time
Today, 02:53
Joined
Jan 22, 2010
Messages
26,374
Here's an idea worth exploring.

Word exposes the following functions:

Application.CheckSpelling
Application.CheckGrammar

They are functions that return True if no errors are found and they don't present a dialog box. All you need is an instance of Word (not a document just an instance of the Word application) and pass the string you would like to check as a parameter. Excel has just CheckSpelling.
 

Misterpiz

New member
Local time
Yesterday, 18:53
Joined
May 9, 2018
Messages
5
as you have it written, spellchecker is checking the entire form, not just tthe one textbox. You may not have noticed, but just so you are aware.

To spellcheck a single control use something like

Code:
 Private Sub txt_notes_LostFocus()

  
 If Not IsNull(txt_notes) Then
    With txt_notes
        .SetFocus
        .SelStart = 0
        .SelLength = Len(txt_notes)
    End With
    DoCmd.SetWarnings False
    RunCommand acCmdSpelling
    DoCmd.SetWarnings True
End If
 
End Sub
note the event - LostFocus

with regards just highlighting words and not invoking the spellchecker window, so far as I am aware this is not possible.

You would have to write your own coding to do this, though I've no idea if it is actually possible - you would need to find a way of opening the windows language dictionary (not sure what it is called), compare word by word and then have some code to select the wrongly spelt word (you would use selstart, sellength to do this) - but that has it's own problems in that (so far as I am aware) the colour of the highlight is with system settings - so not necessarily able to change to yellow.

Then presumably you would need additional code to update the dictionary if the word is a new word and some way of triggering this update (perhaps a shortcut menu?)


This worked wonderfully form my text box. Great coding:D
 

JeanMarc22

New member
Local time
Yesterday, 21:53
Joined
May 26, 2023
Messages
13
I've had this issue where the user calls the Spell Checker to check one textbox but it runs away and checks every field on the form.
I tried bringing the text in a "Zoombox" form to isolate it, similar to the behavious of Shift-F2, but the spell checker would keep checking the form behind after it was done with the active form.
I finally resolved this. I made my "Zoombox" pop-up and modal. Now the Spell checker ends when it is done with that one text box.
My Zoombox form has one text field and a few buttons (Cancel & Close, Update & Close, Spell Check, Change font).
 

Users who are viewing this thread

Top Bottom