Spelling of textbox that has the focus.

M

Michalis J.

I want to run the spelling command only for the textbox that has the focus.
Does anybody have an idea on how I can do this?
Thanks in advance

Michalis
 
M

Michalis J.

Thanks a lot for your reply Alex. This code is suitable for a predefined
textbox. If I want to spellcheck any textbox of a form however I believe I
should write some code to use the Screen.ActiveControl. If you have an idea
of how to do it I would be more than thankfull to hear it.

Michalis
 
P

Paolo

Hi Michalis J.,

Dim ctl As Control

For Each ctl In Screen.ActiveForm.Controls
If ctl.ControlType = acTextBox Then
With ctl.ControlName
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True
End If
Next ctl

This is aircode so you have to test it

HTH Paolo
 
M

Michalis J.

Thank you all gentlement for your support. The code really works with
Douglas's contribution.
However probably I haven't been clear from the begginning but what I whant
to do is to check the content of the textbox on a form where the cursor is
placed. Then the spelling proces should stop. An alternative way is to check
the spelling of all the textboxes in the form as the above code does but only
the current record. Again the spelling process after that should stop.
 
D

Douglas J. Steele

Rather than looping through all of the controls, then, you only need to
worry about the previous control, since presumably you'll have clicked on a
button to invoke the check, which means that the button will be the active
control.

See whether this is what you want:

If Screen.PreviousControl.ControlType = acTextBox Then
With Screen.PreviousControl
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True
End If
 
Top