Avatar of PatHartman
Flag for United States of America

asked on 

Spell check individual control

I would like to run spell check on a few controls (using A2013 runtime) and I don't want the user to have to push a button to make this happen because they just forget.  So, I added the code to call the spell check to the on Exit event (that is the only event that works.  Both Before and After update raise errors and Change isn't even a consideration.) of the controls I want to spellcheck.  Below is the suggested code.  I commented out a few lines that were causing a problem but it still creates a never ending loop.  It seems to make Access forget where it was going when the LostFocus event was interrupted.  The other piece of code from the same website that checks all the controls on a form works fine.  But for this form, I have tab controls and those are interfering with the spell checker when it tries to set focus to a control.

I tried a couple of things such as comparing the .value property to the .oldvalue property.  That works to avoid the spell check when the user is just tabbing through the controls without changing anything but once something is changed, the values are different so the spell checker keeps running.

It would be nice if there were some property that told us where Access thought it was going next so the spell check could just move the focus there but I don't know of any.
Private Sub cmdSpell_Click()
   Dim ctlSpell As Control

   Set ctlSpell = Screen.PreviousControl
   If TypeOf ctlSpell Is TextBox Then
     If IsNull(Len(ctlSpell)) Or Len(ctlSpell) = 0 Then
       ''''MsgBox "There is nothing to spell check."
       Exit Sub
     End If
     With ctlSpell
       .SelStart = 0
       .SelLength = Len(ctlSpell)
     End With
     DoCmd.RunCommand acCmdSpelling
     MsgBox "Spell check is not available for this item."
   End If
 End Sub

Open in new window

Microsoft Access

Avatar of undefined
Last Comment

8/22/2022 - Mon