I searched and read previous posts and could not find anything newer than Access 97.
I am using Access 2007 and a few customers are using 2003.
When I run a spell check from the field I want checked, it goes through all the records and starts displaying suggested changes for other records, and if cancel is selected it leaves the user in the wrong form.
Suggestions?
Thanks,
Dave
Try this within the AfterUpdate event for whichever Text Box:
Code:
If Len(Me.[COLOR="Red"][I]MyTextBoxName[/I][/COLOR] & "") > 0 Then
DoCmd.RunCommand acCmdSpelling
Else
Exit Sub
End If
If you want to Spell check several Text Boxes and in any Form you want then it's better to place the code into a Public Function and have it reside within a Database Code module (not a Form code Module), like this
Code:
Public Function SpellCheckIt()
If Len(Screen.ActiveControl & "") > 0 Then
DoCmd.RunCommand acCmdSpelling
Else
Exit Function
End If
End Function
Then simply place =SpellCheckIt() directly into the AfterUpdate property window for any Text Box you would like to spell check on any Form.
This does what you want, I think. Just replace ControlToBeChecked with your actual textbox name:
Code:
Private Sub ControlToBeChecked_Exit(Cancel As Integer)
With Me!ControlToBeChecked
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 resulted in an error message:
Cannot save to this field...
Recheck Macro... blah blah
or
Recheck macro... other blah blah
or Redefine the function in the module window
Thanks for trying
Dave
Where exactly did you place this? This was intended to be in the textbox OnExit event, in the code behind the form, not in a module. Could you copy and paste it here? There's absolutely nothing in the code that should try to save a field or record.
I replaced the 'ControlToBeChecked' text with the field name: [Type of business?].
I put the code in the after update event for the [Type of business?] field. When you run a spell check and it finds a bad word, it suggests a change. If you accept that change it corrects the original text with the corrected text. That is when it gives the error, trying to save the correction.
Is the problem related to the form and field both being active and trying to save the change.
Don't know why it would matter but this is a memo field.
Thanks again,
Dave
No I am glad that YOU got it working. I usually fight things for 4 or 5 hours before running back here with questions- I have been working on this all week. I hated to tell my customers that they could NOT use spell check- felt much better to tell them it is now working.
I tried again to leave you feedback but the feature says it must be spread around more.
Thanks again- it will be a better weekend without this problem going through my head
From another control (actually a check box and if this checkbox is true) I am using the exact code above to check a text box for spelling. Just in case I am overlooking something I will post it again
Code:
With Me.Taetigkeit
.SetFocus
.SelStart = 1
.SelLength = Len(.Text)
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True
.SelLength = 0
End With
This is all happening in a subform.
When a correction is made I am getting the
The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing MyDatabase from saving the data in the field.
Everything I am talking about is in a subform. (I Hate these subforms with a passion)
My Christmas wish list.
1. User enters data in subform textbox
2. User can if he wants click on the subform checkbox (for the same record) to true
3. If he clicks subform check box to true then textbox is checked for spelling.
Sounds simple.
So here is the code I am working with. The surrounding code just gets the users current language for spelling. Then sets it to US English. Then after it is finished it sets it back to the users original settings.
Code:
If checkbox then
Dim current_language As Integer
current_language = Application.GetOption("Spelling dictionary language")
Application.SetOption "Spelling dictionary language", 1033
With Me.Textbox
.SetFocus
.SelStart = 1
.SelLength = Len(.Text)
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True
.SelLength = 0
End With
Application.SetOption "Spelling dictionary language",
current_language
end if
First where to put this. I cannot put this in the Afterupdate of textbox or checkbox cause I get this..
The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing MyDatabase from saving the data in the field.
To avoid this error I can put it in the On-Exit. But then;
1. If the user clicks in the main form the on_exit does not fire.
2. Even Worse if the user moves immediately to a new record, Access tries to spell check every textbox until you close down the mdb.
Could someone please assist me with my subform nightmare?
To get things kinda working I put my spell check into the afterupdate of the subform. This is more of a hack than a solution because this only is fired when the user leaves the subform (as far as i can work out) and this causes problems when the user adds an entry to the subform with a spelling mistake and then changes forms. Once again it tries to spell check everything.
Does anybody have a solution here of where I can put this dam spell check?
Or how can I capture the error? I do not see where it comes from?
I have another hack. The problem is while ever the user is in the subform Access will not let the spell checker update it. So I have introduced the timer.
When the users clicks the check box for the subforms record the last thing that is done is that a TimerInterval = 100 is added to the main form.
In the timer routine i have a Setfocus to something in the main form thus firing the subforms afterupdate and thus the spell check.
This works ok as long as you do not delete any spelling mistakes.
if you do then the timer events setfocus errors with 2110. So I just clear that error.
This is my variation of a working solution to check only the current (active) textbox and nothing else. "bolTextChanged" is set to "true" when the "On Change Event" occurs so that the spell checker is not triggered unless the text is changed. Of course, "bolTextChanged" can be removed if you want spell check to run every time the textbox is entered.
Code:
Private Sub Text10_LostFocus()
DoCmd.SetWarnings False
With Me.Text10
.SetFocus
.SelStart = 0
.SelLength = Nz(Len(Me.Text10), 0)
If Nz(Len(Me.Text10), 0) > 0 And bolTextChanged Then Me.Text10.SetFocus: DoCmd.RunCommand acCmdSpelling
End With
DoCmd.SetWarnings True
End Sub