Spell Check Specific Field from a module (1 Viewer)

Eccles

New member
Local time
Today, 15:35
Joined
Oct 7, 2020
Messages
4
Hello,
I am new to access and am currently making a data base where I have a button on a on the main form header which when clicked calls a function in a module to spell check a specific field in a subform. The code when highlights the text as it should however the DoCmd.RunCommand acCmdSpelling doesnt seem to actually check the spelling? Please see the code below. Any help would be great!

Public Function FUNC_SpellCheck()

On Error Resume Next

Dim ctlSpell As Control



Set ctlSpell = [Forms]![MainForm]![SubForm1]![Subform2].[Form]![TextField]

If TypeOf ctlSpell Is TextBox Then

If IsNull(Len(ctlSpell)) Or Len(ctlSpell) = 0 Then

ctlSpell.SetFocus

Exit Function

End If

With ctlSpell

.SetFocus

.SelStart = 0

.SelLength = Len(ctlSpell)

DoCmd.RunCommand acCmdSpelling

End With

End If


End Function
 

Isaac

Lifelong Learner
Local time
Today, 08:35
Joined
Mar 14, 2017
Messages
8,738
Remove On Error Resume Next, first of all. Putting that code is usually a bad idea. It means you are telling Access, "If any errors come up, don't tell me about them, and don't tell me what they were. Just finish running the code anyway as best as you can".

Once you can generate a runtime error, you can click Debug and see what the offending line of code is. I glanced at your code but really, the best next step for you is to generate a meaningful error so you can then take the educational opportunity to troubleshoot.

(I will say that a regular form, which is not in popup or modal view, and as long as you have NOT disabled the ribbon toolbar, once you setfocus to a textbox control, then run that command, it would normally bring up the spelling prompt. And those 2 lines of code...Me.Textbox1.Setfocus, DoCmd.RunCommand acCmdSpelling would be all you'd have to do, if the environment is just right).
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:35
Joined
Oct 29, 2018
Messages
21,359
Hi. Welcome to AWF!

What is it doing instead?
 

Eccles

New member
Local time
Today, 15:35
Joined
Oct 7, 2020
Messages
4
Hi, Thank you very much for the response! I have removed the on error!

When I use the debugger no errors come up. I can see the relevant text is highlighted then when the I go on to the DoCmd.RunCommand acCmdSpelling line it shows the spell check complete text box but I it doesnt actually spell check the text.

I have put FUNC_SpellCheck on a button in the subform and this works properly so not sure why its not working from the main form?
 

Isaac

Lifelong Learner
Local time
Today, 08:35
Joined
Mar 14, 2017
Messages
8,738
What if you just reduced all this to two lines - one line to set focus to the control, the next to run the spelling command.
 

Isaac

Lifelong Learner
Local time
Today, 08:35
Joined
Mar 14, 2017
Messages
8,738
then when the I go on to the DoCmd.RunCommand acCmdSpelling line it shows the spell check complete text box but I it doesnt actually spell check the text.
What do you mean by that? Just "spell check is complete" message box?

That means the spell checker did work.

As far as whether or not it "caught" something that you believe was misspelled, that's more a matter of the spell check client options, like Ignore uppercase, ignore hyphenated words, add to dictionary, etc.
 

Eccles

New member
Local time
Today, 15:35
Joined
Oct 7, 2020
Messages
4
Yeah the spell check command goes through and the conformation message box comes up but it seems like it doesn't recognise the words that are highlighted? I used the text "Does ths spll chck wrk" in the field and then tried both the button on the subform and on the main form. When clicked on the subform it recognises the text and shows me the corrections, however from the main form header it doesn't show any corrections that need to be made?

Hopefully this makes sense?
 

Eccles

New member
Local time
Today, 15:35
Joined
Oct 7, 2020
Messages
4
What if you just reduced all this to two lines - one line to set focus to the control, the next to run the spelling command.
Do you mean something like this?

Public Function FUNC_SpellCheck()
Dim ctlSpell As Control

Set ctlSpell = [Forms]![MainForm]![SubForm1]![Subform2].[Form]![TextField]

If TypeOf ctlSpell Is TextBox Then

If IsNull(Len(ctlSpell)) Or Len(ctlSpell) = 0 Then

Exit Function

End If

ctlSpell.SetFocus

DoCmd.RunCommand acCmdSpelling

End With

End If

End Function

Does the text not need to be highlighted for the command to only spell check the specific field?
Thank you for help!
 
Last edited:

Isaac

Lifelong Learner
Local time
Today, 08:35
Joined
Mar 14, 2017
Messages
8,738
I was thinking maybe:
Code:
Public Function FUNC_SpellCheck()
[Forms]![MainForm]![SubForm1]![Subform2].[Form]![TextField].SetFocus
DoCmd.RunCommand acCmdSpelling
End Function

The reason why I suggest this is two-fold.
1) Your function doesn't accept a parameter anyway, and therefore, has no particular value as a function...It can't be re-used anywhere else, as-is, right at the present moment, anyway.
2) Just to eliminate any extra "noise" from the troubleshooting scenario (related to how all the other stuff in your function is working or not working), and instead, see if the 'basic approach' even works well for you. (I think you have some mistakes there, like checking for IsNull(Len)), but let's start with this).

No, the text does not need to be highlighted for the spell command to work effectively on the control.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:35
Joined
May 7, 2009
Messages
19,175
the textbox (TextField) on the subform must not be blank for the Spelling to work.
it must contain wrong spelling also for the spelling form to show up.
you also need to set Focus on each Form/subform.
Code:
Public Function FUNC_SpellCheck()

    On Error Resume Next
    Dim ctlSpell As Control
    Set ctlSpell = [Forms]![MainForm]![subForm1]![Subform2].[Form]![TextField]
    [Forms]![MainForm].SetFocus
    [Forms]![MainForm]![subForm1].SetFocus
    [Forms]![MainForm]![subForm1]![Subform2].SetFocus
    If TypeOf ctlSpell Is TextBox Then
        If IsNull(Len(ctlSpell)) Or Len(ctlSpell) = 0 Then
            ctlSpell.SetFocus
            Exit Function
        End If
        With ctlSpell
            .SetFocus
            .SelStart = 0
            .SelLength = Len(ctlSpell)
            DoCmd.RunCommand acCmdSpelling
        End With
    End If
End Function
 

Users who are viewing this thread

Top Bottom