I added the following code in the AfterUpdate event of a textbox in an MS Access form:
Private Sub txtComments_AfterUpdate()
With Me!txtComments
.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
End Sub
This runs a spell check when the user exits the field. It partially works. It opens the spell check dialogue, and locates the first error. The problem is, when you click Ignore, Change, etc to handle/repair the spelling error, the code fails and the following error box appears:
"The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Microsoft Office Access from saving the data in the field."
I tried adding record-saving code before the spell check code:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
but this didn't solve it.
This code works as the On Exit event (instead of After Update).
Private Sub txtComments_Exit(Cancel As Integer)
With Me!txtComments
.SetFocus
If Len(.value) > 0 Then
.SelStart = 1
.SelLength = Len(.value)
DoCmd.RunCommand acCmdSpelling
.SelLength = 0
End If
End With
End Sub