Solved Spell Check 3 text boxes (1 Viewer)

oxicottin

Learning by pecking away....
Local time
Today, 09:31
Joined
Jun 26, 2007
Messages
856
Hello, I have 3 text boxes that are memo fields and I added a button on my form to spell check all 3. For some reason it spell checks the first 2 and skips the 3rd (txtQualityIssues) one and wont check it. The spelling is correct so that's not it, what could it be? Thanks!

Code:
Private Sub cmdSpellCheckIssues_Click()
'--------------------------------------------------------------------------------------------------
'Spell checks the 3 issues memo fields one after the other
'--------------------------------------------------------------------------------------------------

  Dim blRet As Boolean, arrCtls As Variant, i As Integer

  arrCtls = Array("txtProductionProblems", "txtMaintenanceIssues", "txtQualityIssues")
  DoCmd.SetWarnings False
  For i = 0 To UBound(arrCtls) - 1
    With Me(arrCtls(i))
      If Len(.Value & vbNullString) > 0 Then
        .SetFocus
        .SelStart = 1
        .SelLength = Len(.Value)
        DoCmd.RunCommand acCmdSpelling
        .SelLength = 0
      End If
    End With
  Next i
  blRet = (Err = 0)
End Sub
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 09:31
Joined
Feb 19, 2002
Messages
43,266
I'm not sure that code is working the way you think it should. Here's two subs I use. One when I want to spell check all the text boxes and one that does just one textbox. FYI, I use macros to turn warnings Off and On so that when I turn warnings off, I also turn the hourglass on and vice versa. The macro just makes sure that both actions happen and it gives me an easy way to turn warnings back on if I end up stopping the code while testing before the warnings are turned back on. For a developer, having warnings off is a recipe for disaster and it only has to happen to you once to scar you for life. The hourglass is an annoying reminder that warnings are off so I NEVER, EVER forget again. If you forget to turn warnings back on and you make changes to objects and close them, Access silently discards the changes and doesn't prompt you to save.


Code:
Public Sub cmdSpell_EntireForm(frm)
   Dim ctlSpell As Control
   Dim ctlName As String

   On Error GoTo Err_Proc

  DoCmd.RunMacro "mWarningsOff"        'turn warnings off to surpress "complete" message
   ' Enumerate Controls collection.
  
   For Each ctlSpell In frm.Controls
     If TypeOf ctlSpell Is TextBox Then
       If Len(ctlSpell) > 0 Then
         With ctlSpell
           .SetFocus
           .SelStart = 0
           .SelLength = Len(ctlSpell)
         End With
         DoCmd.RunCommand acCmdSpelling
         If ctlName = ctlSpell.name Then
            GoTo Exit_Proc
         Else
            ctlName = ctlSpell.name
         End If
       End If
     End If
   Next
       DoCmd.RunMacro "mWarningsOn"

Exit_Proc:
   On Error GoTo 0
   Exit Sub

Err_Proc:

    Select Case Err.Number
        Case Else
            MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdSpell_EntireForm of Module mSpellCheckForRuntime"
    End Select
 End Sub

Public Sub cmdSpell_SingleControl(cntl As Control)
    Dim ctlSpell As Control
    
   On Error GoTo Err_Proc

    Set ctlSpell = cntl 'Screen.PreviousControl
    If IsNull(Len(ctlSpell)) Or Len(ctlSpell) = 0 Then
        'MsgBox "There is nothing to spell check."
        'ctlSpell.SetFocus
        Exit Sub
    End If
            
    DoCmd.RunMacro "mWarningsOff"        'turn warnings off to surpress "complete" message
    With ctlSpell
      .SetFocus
      .SelStart = 0
      .SelLength = Len(ctlSpell)
    End With
    DoCmd.RunCommand acCmdSpelling
    DoCmd.RunMacro "mWarningsOn"

Exit_Proc:
   On Error GoTo 0
   Exit Sub

Err_Proc:

    Select Case Err.Number
        Case Else
            MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdSpell_SingleControl of Module mSpellCheckForRuntime"
    End Select
 End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:31
Joined
Sep 21, 2011
Messages
14,288
With only 3 textboxes, it would not hurt to walk through the code with F8?
 

oxicottin

Learning by pecking away....
Local time
Today, 09:31
Joined
Jun 26, 2007
Messages
856
I only need to check the 3 text boxes and I need to spell check one after another with a press of the button. I got the below code working correctly with @Minty suggestion for the 3 text boxes and I added true to warnings....

Code:
Private Sub cmdSpellCheckIssues_Click()
'--------------------------------------------------------------------------------------------------
'Spell checks the 3 issues memo fields one after the other
'--------------------------------------------------------------------------------------------------

  Dim blRet As Boolean, arrCtls As Variant, i As Integer

  arrCtls = Array("txtProductionProblems", "txtMaintenanceIssues", "txtQualityIssues")
  DoCmd.SetWarnings False
  For i = 0 To UBound(arrCtls) 
    With Me(arrCtls(i))
      If Len(.Value & vbNullString) > 0 Then
        .SetFocus
        .SelStart = 1
        .SelLength = Len(.Value)
        DoCmd.RunCommand acCmdSpelling
        .SelLength = 0
      End If
    End With
  Next i
  blRet = (Err = 0)
  DoCmd.SetWarnings True
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:31
Joined
Sep 21, 2011
Messages
14,288
My point was, if you had taken the trouble to walk through the code, after all it is only 3 iterations, not 300, then the error would have been obvious?
 

Users who are viewing this thread

Top Bottom