Spell Check not working

access7

Registered User.
Local time
Today, 20:47
Joined
Mar 15, 2011
Messages
172
Hello

I hope someone can help... I have attached my database and pasted the code below... for some reason I keep getting the following error message:
'Run time error '2046' - The command or action 'spelling' isn't available now'

Here is the code:

Private Sub CmdSpellChecker_Click()

ControlEnabler True (These modules are arrays which set the Enabled /
ControlLocker False (Locked properties of the controls)

With Me.txtNotes

Me.txtNotes.SetFocus

If Len(.Value) > 0 Then
DoCmd.SetWarnings False
.SelStart = 1
.SelLength = Len(.Value)
DoCmd.RunCommand acCmdSpelling
.SelLength = 0
DoCmd.SetWarnings True
End If

End With

ControlEnabler False
ControlEnabler True
 

Attachments

Have you tried not setting the SelStart and SelLength? Just set focus on that control and do spelling? It seems to work for me (but I am not using your database because I am only on 2003 here at work and don't have any newer one here to handle accdb files).

And just an FYI for you. Did you know you could use the same button for all fields just by changing the set focus from what you have to this:

Screen.PreviousControl.SetFocus

so someone could put their cursor in any control and then click the button and it would use that control. You would probably need to check to see if the previous control is a type that can be checked so like:
Code:
Dim strName As String
 
strName = Screen.PreviousControl.Name
 
If Me.Controls(strName).ControlType = acTextBox Then
   Me.Controls(strName).SetFocus
  DoCmd.RunCommand acCmdSpelling
End If

But just a word of caution - RunCommands can be affected by what's happening so sometimes they don't act exactly like you want.
 
Thanks for the advice, sorry it's taken a while to reply, I've not had much time on the database this week. I have tried the code above with a slight variation as below (I have set focus to just the one control, rather than your suggestion of 'previous' control - I wasn't sure with this particular field being on a sub form whether that would cause issues, also, it is the only field on the subform where users can enter data, the other fields are combo boxes / list boxes).

Private Sub CmdSpellChecker_Click()

ControlEnabler True
ControlLocker False

Dim strName As String

strName = Me.txtNotes

If Me.Controls(strName).ControlType = acTextBox Then
Me.Controls(strName).SetFocus
DoCmd.RunCommand acCmdSpelling
End If

ControlEnabler False
ControlEnabler True

End Sub

I am getting the following error 'run-time error 2465; 'Contact Management System can't find the field 'Testing spell check' referred to in your expression'...

I'm not sure how to adapt the code first of all as the field 'txtNotes' is actually a memo field rather than a text box - does this make a difference?
Also, the 'Testing spell check' is the text entered in the txtNotes field, rather than the field itself? I am therefore confused by the error message, it would appear that it is finding the correct field (otherwise it wouldn't know what was written in it), however, it seems to think that is the name of the field??

Does anyone have any ideas where I might be going wrong with the code in relation to what I have explained??

Many Thanks
 

Users who are viewing this thread

Back
Top Bottom