How to force Spellcheck?

P

PayeDoc

Hello All

Is it possible to force a spellcheck every time a textbox is edited.
I guess the best way would be if there is a VBA command that I could put in
the textbox's AfterUpdate event: but is there one? The only other thing I
thought of is using a macro with SendKeys, but this seems crude and risky.

Hope someone can help.
Many thanks
Leslie Isaacs
 
P

PayeDoc

Sorry about this - I should have googled it first - just found:
DoCmd.RunCommand acCmdSpelling
.... which seems to do the trick!

Only problem is that, where I have used this as the afterupdate event of a
textbox on a form that is opened in singleform view, the spellchecj doesn't
restrict itself to that particular texbox or to the current record. I know I
can cancel the spellcheck as soon as it leaves the textbox I want checked,
but it's a nuisance to have to reselect the record each time!

I googled a bit more, and found the code below, whch works OK except that it
it keeps running - it won't let me out of the textbox!

How do I stop this from running after it has run once?

Thanks for any help
Leslie Isaacs

The code I found:

Private Sub YOURFIELDNAME_Exit(Cancel As Integer)
Dim strSpell
strSpell = YOURFIELDNAME
If IsNull(Len(strSpell)) Or Len(strSpell) = 0 Then
Exit Sub
'Source:: Sikh Philosophy Network
http://www.sikhphilosophy.net/showthread.php?t=13686 (How Do I Invoke Spell
Check from Within Access VBA)
End If
With YOURFIELDNAME
..SetFocus
..SelStart = 0
..SelLength = Len(strSpell)
End With
DoCmd.SetWarnings False
'Source:: Sikh Philosophy Network
http://www.sikhphilosophy.net/showthread.php?t=13686 (How Do I Invoke Spell
Check from Within Access VBA)
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True
End Sub
 
M

Marshall Barton

PayeDoc said:
Is it possible to force a spellcheck every time a textbox is edited.
I guess the best way would be if there is a VBA command that I could put in
the textbox's AfterUpdate event: but is there one? The only other thing I
thought of is using a macro with SendKeys, but this seems crude and risky.


Me.textbox.SelStart = 0
Me.textbox.SelLength = Len(Me.textbox)
DoCmd.RunCommand acCmdSpelling


The text box must have the focus before doing the above.
Since you are in the text box's AfterUpdate event, this is
not an issue. However, if you want to spell check a
different text box, you would need to use SetFocus first.
 
M

Marshall Barton

PayeDoc said:
Sorry about this - I should have googled it first - just found:
DoCmd.RunCommand acCmdSpelling
... which seems to do the trick! [snip]
I googled a bit more, and found the code below, whch works OK except that it
it keeps running - it won't let me out of the textbox!
[snip]


Argghhh, I forgot about that problem. The AfterUpdate event
can not be used for this because SpellCheck modifies the
text box's .Text property, which triggers the text box's
chain of events all over again.

You can use an event for some other control (e.g. a command
button) or a menu/toolbar item just by using SetFocus and
the code I posted.
 
L

Leslie Isaacs

Hello Marshall
Thanks for your replies.
So from what you're saying the spellcheck cannot be 'forced' (unless an
event is created for another control that is expected to fire). Might it be
possible instead to have some yes/no flag in the code that is initially set
to 'yes' (as the first step of the spellcheck code), which would be set to
'no' after the spellcheck has run: and with the spellcheck command itself
made conditional on the flag being set to 'yes'?
Does this sound feasible?
Les


Marshall Barton said:
PayeDoc said:
Sorry about this - I should have googled it first - just found:
DoCmd.RunCommand acCmdSpelling
... which seems to do the trick! [snip]
I googled a bit more, and found the code below, whch works OK except that it
it keeps running - it won't let me out of the textbox!
[snip]


Argghhh, I forgot about that problem. The AfterUpdate event
can not be used for this because SpellCheck modifies the
text box's .Text property, which triggers the text box's
chain of events all over again.

You can use an event for some other control (e.g. a command
button) or a menu/toolbar item just by using SetFocus and
the code I posted.
 
M

Marshall Barton

Leslie said:
So from what you're saying the spellcheck cannot be 'forced' (unless an
event is created for another control that is expected to fire). Might it be
possible instead to have some yes/no flag in the code that is initially set
to 'yes' (as the first step of the spellcheck code), which would be set to
'no' after the spellcheck has run: and with the spellcheck command itself
made conditional on the flag being set to 'yes'?


Interesting question. I really don't want to say it can't
be done, but I'm going to have to study it before I can
figure out a way to do it or explain why it can't be done.
Might take a while so be patient.
 
G

Gina Whipp

Thinking out loud here... What about you created a DateModified field and
put this on the On_Exit of the field?

If Not IsNull(Me.TextBox) And DateValue([txtDateModified]) = Date Then
Me.TextBox.SelStart = 0
Me.TextBox.SelLength = Len(Me.TextBox)
DoCmd.RunCommand acCmdSpelling
End If


--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
G

Gina Whipp

oops forgot... DateModified should be put On_Dirty of the form to update to
todays date (Now()) if changes are made

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Gina Whipp said:
Thinking out loud here... What about you created a DateModified field and
put this on the On_Exit of the field?

If Not IsNull(Me.TextBox) And DateValue([txtDateModified]) = Date Then
Me.TextBox.SelStart = 0
Me.TextBox.SelLength = Len(Me.TextBox)
DoCmd.RunCommand acCmdSpelling
End If


--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
L

Leslie Isaacs

Hello Gina

Many thanks for your suggestion.

Not sure I undestand it though! Wouldn't [txtDateModified] be updated evry
time the spellcheck ran (assuming the spellcheck changed something) - or
would the On_Dirty event not fire after the spellcheck?

I will try it and see when I'm back in the office!

Thanks again
Les


Gina Whipp said:
oops forgot... DateModified should be put On_Dirty of the form to update to
todays date (Now()) if changes are made

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Gina Whipp said:
Thinking out loud here... What about you created a DateModified field and
put this on the On_Exit of the field?

If Not IsNull(Me.TextBox) And DateValue([txtDateModified]) = Date Then
Me.TextBox.SelStart = 0
Me.TextBox.SelLength = Len(Me.TextBox)
DoCmd.RunCommand acCmdSpelling
End If


--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Marshall Barton said:
PayeDoc wrote:
Is it possible to force a spellcheck every time a textbox is edited.
I guess the best way would be if there is a VBA command that I could put
in
the textbox's AfterUpdate event: but is there one? The only other thing I
thought of is using a macro with SendKeys, but this seems crude and
risky.


Me.textbox.SelStart = 0
Me.textbox.SelLength = Len(Me.textbox)
DoCmd.RunCommand acCmdSpelling


The text box must have the focus before doing the above.
Since you are in the text box's AfterUpdate event, this is
not an issue. However, if you want to spell check a
different text box, you would need to use SetFocus first.
 
G

Gina Whipp

Leslie,

Just for fun I tested that theory... Putting Date Modified in the On_Dirty
event of the form only causes it to update ONCE to todays date and in my
code that is ALL it is looking for is the DATE not the TIME. Spellcheck
will only be triggered if you make a change in that field, no other field
triggers it. (Remember, Spell Check is only attached for THAT field.)

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Leslie Isaacs said:
Hello Gina

Many thanks for your suggestion.

Not sure I undestand it though! Wouldn't [txtDateModified] be updated
evry time the spellcheck ran (assuming the spellcheck changed something) -
or would the On_Dirty event not fire after the spellcheck?

I will try it and see when I'm back in the office!

Thanks again
Les


Gina Whipp said:
oops forgot... DateModified should be put On_Dirty of the form to update to
todays date (Now()) if changes are made

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Gina Whipp said:
Thinking out loud here... What about you created a DateModified field and
put this on the On_Exit of the field?

If Not IsNull(Me.TextBox) And DateValue([txtDateModified]) = Date Then
Me.TextBox.SelStart = 0
Me.TextBox.SelLength = Len(Me.TextBox)
DoCmd.RunCommand acCmdSpelling
End If


--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

PayeDoc wrote:
Is it possible to force a spellcheck every time a textbox is edited.
I guess the best way would be if there is a VBA command that I could put
in
the textbox's AfterUpdate event: but is there one? The only other thing I
thought of is using a macro with SendKeys, but this seems crude and
risky.


Me.textbox.SelStart = 0
Me.textbox.SelLength = Len(Me.textbox)
DoCmd.RunCommand acCmdSpelling


The text box must have the focus before doing the above.
Since you are in the text box's AfterUpdate event, this is
not an issue. However, if you want to spell check a
different text box, you would need to use SetFocus first.
 
M

Marshall Barton

Leslie said:
So from what you're saying the spellcheck cannot be 'forced' (unless an
event is created for another control that is expected to fire). Might it be
possible instead to have some yes/no flag in the code that is initially set
to 'yes' (as the first step of the spellcheck code), which would be set to
'no' after the spellcheck has run: and with the spellcheck command itself
made conditional on the flag being set to 'yes'?


I now believe that it is impossible to use the AfterUpdate
event because spell check resets the text box's Text
property. Setting the Text property invokes the text box's
BeforeUpdate procedure, which then causes an error because
the original update sequence has not finished. In other
words, the AfterUpdate event must be completed before the
Text property can be modified.

The closest you could come to doing this without using a
separate control to trigger it would be to use the Exit
event.
 
L

Leslie Isaacs

Marshall

Many thanks for looking into this.

From what you have said I guess then I need to put the code you suggested:

Me.textbox.SelStart = 0
Me.textbox.SelLength = Len(Me.textbox)
DoCmd.RunCommand acCmdSpelling

... as the OnExit event of the textbox:? And this event will only fire
each time the textbox is 'exited' - which is not necessarily every time it
is updated (e.g. by being spellchecked)? I'll try that tomorrow when I'm in
the office. I also have to look again at Gina's suggestion, which I didn't
fully follow but suspect may be very helpful!

Almost as an aside, if the textbox name is, say, mytexbox, what's the
difference between
Me.mytextbox.SelStart = 0
and
mytexbox.SelStart = 0

I'll let you know how I get on.
Les
 
M

Marshall Barton

Leslie said:
From what you have said I guess then I need to put the code you suggested:

Me.textbox.SelStart = 0
Me.textbox.SelLength = Len(Me.textbox)
DoCmd.RunCommand acCmdSpelling

... as the OnExit event of the textbox:? And this event will only fire
each time the textbox is 'exited' - which is not necessarily every time it
is updated (e.g. by being spellchecked)? I'll try that tomorrow when I'm in
the office. I also have to look again at Gina's suggestion, which I didn't
fully follow but suspect may be very helpful!

Almost as an aside, if the textbox name is, say, mytexbox, what's the
difference between
Me.mytextbox.SelStart = 0
and
mytexbox.SelStart = 0

The difference between using Me and not using it when
refering to a control on the form is that it disambiguates
the text box name from other things (e.g. VBA variable) that
have the same name. I make a serious effort to never use
the same name for two different things, so it just helps me
remember that the name is for a form property or method
(controls are automatically added to a form's list of
properties).

If you can keep all that straight in your mind, then the use
of Me with a control name is not required.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top