Spell check only a single field in a specific record (1 Viewer)

WinDancer

Registered User.
Local time
Today, 05:21
Joined
Oct 29, 2004
Messages
290
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
 

CyberLynx

Stuck On My Opinions
Local time
Today, 05:21
Joined
Jan 31, 2008
Messages
585
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.

.
 

WinDancer

Registered User.
Local time
Today, 05:21
Joined
Oct 29, 2004
Messages
290
This works, but checks every record in the form's underlying table...
 

missinglinq

AWF VIP
Local time
Today, 08:21
Joined
Jun 20, 2003
Messages
6,423
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
 

WinDancer

Registered User.
Local time
Today, 05:21
Joined
Oct 29, 2004
Messages
290
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
 

missinglinq

AWF VIP
Local time
Today, 08:21
Joined
Jun 20, 2003
Messages
6,423
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.
 

WinDancer

Registered User.
Local time
Today, 05:21
Joined
Oct 29, 2004
Messages
290
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
 

WinDancer

Registered User.
Local time
Today, 05:21
Joined
Oct 29, 2004
Messages
290
Here is the code....


Private Sub Nature_of_Business__AfterUpdate()
With Me![Nature of Business?]

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
 

missinglinq

AWF VIP
Local time
Today, 08:21
Joined
Jun 20, 2003
Messages
6,423
Try moving the code to the Exit event of the textbox, as it was in the code I posted.
 

WinDancer

Registered User.
Local time
Today, 05:21
Joined
Oct 29, 2004
Messages
290
SWEEEEET!
Thanks- I appreciate the time you took to help :)
 

WinDancer

Registered User.
Local time
Today, 05:21
Joined
Oct 29, 2004
Messages
290
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 :)
 

kate10123

Registered User.
Local time
Today, 13:21
Joined
Jul 31, 2008
Messages
185
This code is exactly what I am looking for but I want to put it behind a button as opposed to the actual textbox.

How can I edit the code for this?

Thanks

Kate
 

darbid

Registered User.
Local time
Today, 14:21
Joined
Jun 26, 2008
Messages
1,428
Hello all,

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.
The textbox has no events attached to it ( so no before/after or lost focus events)

What is interesting is if I highlight the text and press F7 there is no problem.

Could someone please assist with why I cannot use the spell checker here without getting the error message.
 

darbid

Registered User.
Local time
Today, 14:21
Joined
Jun 26, 2008
Messages
1,428
Ok the F7 test should of told me what the problem was.

I added a test button and ran the check spelling and there is no problem.

The problem is the checkbox_click event which runs the check spelling of the textbox.

I am assuming that if I can get the bound checkbox "saved" or get it updated before I run the checkspelling I am good.

How do I do this?
 

darbid

Registered User.
Local time
Today, 14:21
Joined
Jun 26, 2008
Messages
1,428
I am kinda bumping this thread and need help.

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?
 

darbid

Registered User.
Local time
Today, 14:21
Joined
Jun 26, 2008
Messages
1,428
It has been a while since I visited this problem.

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?
 

darbid

Registered User.
Local time
Today, 14:21
Joined
Jun 26, 2008
Messages
1,428
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.
 

Steve R.

Retired
Local time
Today, 08:21
Joined
Jul 5, 2006
Messages
4,703
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
 

Users who are viewing this thread

Top Bottom