Using Call to Spell Check Before Update - SetFocus Error? (1 Viewer)

dgreen

Member
Local time
Today, 09:59
Joined
Sep 30, 2018
Messages
397
Visual of what's happening. I put in some text in the Notes field and leave the cell. The call procedure to spell check, running on a Before_Update, gets to the .SetFocus line and then errors. What am I missing?
1587141360668.png
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 07:59
Joined
Oct 29, 2018
Messages
21,457
Hi. Just for fun, try moving your code from BeforeUpdate to AfterUpdate.
 

dgreen

Member
Local time
Today, 09:59
Joined
Sep 30, 2018
Messages
397
But now it's spell checking all of the Notes field values and not just stopping at the me.Notes I just left.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:59
Joined
Oct 29, 2018
Messages
21,457
But now it's spell checking all of the Notes field values and not just stopping at the me.Notes I just left.
Just a guess but perhaps you could modify your function to also accept an argument to specify which record to spell check. Just a thought...
 

dgreen

Member
Local time
Today, 09:59
Joined
Sep 30, 2018
Messages
397
You mean something like below? If yes, that was already in place.
Code:
Private Sub Notes_AfterUpdate()
    Call SpellChecker(Me.Notes)
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:59
Joined
Oct 29, 2018
Messages
21,457
You mean something like below? If yes, that was already in place.
Code:
Private Sub Notes_AfterUpdate()
    Call SpellChecker(Me.Notes)
End Sub
No. More like:

Call SpellChecker(Me.ID)
 

dgreen

Member
Local time
Today, 09:59
Joined
Sep 30, 2018
Messages
397
With the previous way, I was telling the Call to spell check a specific text box. If I change the call to point to the primary key of the record, how will it know which field to check?

How you would you have me modify the below Public Function?

Code:
Option Compare Database
Option Explicit

Public Function SpellChecker(txt As TextBox) As Boolean
    On Error GoTo Err_SpellChecker
    
    With txt
        .SetFocus
        .SelStart = 0
        .SelLength = Len(.Text)
        SpellChecker = Len(.Text) > 0
    End With
    With DoCmd
        .SetWarnings False
        .RunCommand acCmdSpelling
    End With
    
Exit_SpellChecker:
    DoCmd.SetWarnings True
    Exit Function
    
Err_SpellChecker:
    Select Case Err.Number
        Case 2046
            ' not available
        Case Else
            MsgBox "Error No.: " & Err.Number & vbNewLine & vbNewLine & _
                   "Description: " & Err.Description & vbNewLine & vbNewLine & _
                   "Function: SpellChecker" & vbNewLine & _
                   IIf(Erl, "Line No: " & Erl & vbNewLine, "") & _
                   "Module: basTest", , "Error: " & Err.Number
    End Select
    Resume Exit_SpellChecker
    
End Function
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:59
Joined
Oct 29, 2018
Messages
21,457
With the previous way, I was telling the Call to spell check a specific text box. If I change the call to point to the primary key of the record, how will it know which field to check?

How you would you have me modify the below Public Function?

Code:
Option Compare Database
Option Explicit

Public Function SpellChecker(txt As TextBox) As Boolean
    On Error GoTo Err_SpellChecker
    
    With txt
        .SetFocus
        .SelStart = 0
        .SelLength = Len(.Text)
        SpellChecker = Len(.Text) > 0
    End With
    With DoCmd
        .SetWarnings False
        .RunCommand acCmdSpelling
    End With
    
Exit_SpellChecker:
    DoCmd.SetWarnings True
    Exit Function
    
Err_SpellChecker:
    Select Case Err.Number
        Case 2046
            ' not available
        Case Else
            MsgBox "Error No.: " & Err.Number & vbNewLine & vbNewLine & _
                   "Description: " & Err.Description & vbNewLine & vbNewLine & _
                   "Function: SpellChecker" & vbNewLine & _
                   IIf(Erl, "Line No: " & Erl & vbNewLine, "") & _
                   "Module: basTest", , "Error: " & Err.Number
    End Select
    Resume Exit_SpellChecker
    
End Function
Hi. I already left the office. It was just a thought. You could also modify it to pass two arguments: notes and id.

I don't even understand how it's checking all the records now because I didn't really look at the function code.

Sent from phone...
 

missinglinq

AWF VIP
Local time
Today, 10:59
Joined
Jun 20, 2003
Messages
6,423
Here's code to add to your Form to do this:

Code:
Private Sub Notes_Exit(Cancel As Integer)

With Me!Notes

  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

Maybe you can modify it into a Function, if need be.

Linq ;0)>
 

dgreen

Member
Local time
Today, 09:59
Joined
Sep 30, 2018
Messages
397
The negative of running this code on Exit, is if I click on a record entered by someone else, say just to view it, I'll be spell checking other people's spelling errors vice just mine for the records I just entered.

Notes_Exit(Cancel As Integer)
 

Users who are viewing this thread

Top Bottom