Spell check in subform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tuxalot
    New Member
    • Feb 2009
    • 200

    #1

    Spell check in subform

    I am using this code to perform spell checks (not sure where I got it, but it works a peach):

    Code:
    Public Function SpellChecker(Calling As Form)
        On Error GoTo Err_SpellChecker
        Dim ctlSpell As Control
        Dim Incoming As String, Outgoing As String
    
        DoCmd.SetWarnings False
    
        Set ctlSpell = Calling.ActiveControl
        If (ctlSpell.Locked) Then
            Line1 = "Cannot spell check. Field is read-only"
            mbResult = MsgBox("OK", "", "", Line1)
        Else
    
            If (ctlSpell) > 0 Then
                Incoming = ctlSpell
                With ctlSpell
                    .SetFocus
                    .SelStart = 0
                    .SelLength = Len(ctlSpell)
                End With
                DoCmd.RunCommand acCmdSpelling
                Outgoing = ctlSpell
            End If
            ' See if any changes were made 09/29/04
            If (Incoming <> Outgoing) Then
                ' Notify user that changes
                ' were made, if you want to,
                ' or give Bronx cheer
            End If
        End If
    
        DoCmd.SetWarnings True
    
    exit_SpellChecker:
        Exit Function
    
    Err_SpellChecker:
        Select Case Err.Number
            Case 2424
                'MsgBox "change rs"
                Exit Function
            Case 438
                MsgBox "438 error"
            Case Else
                MsgBox Err.Number & "-" & Err.Description
                Resume exit_SpellChecker
        End Select
    End Function
    Setup:

    The textboxes that are spell checked reside on a subform that has it's recordsource dynamically created by an option group on the parent form (criteria in query changes by the value of the option group button selected).

    Problem:

    If a textbox that has focus contains a misspelled word and the option group is clicked, ctlSpell does not exist and it throws a 2424 error. Strangely, I tested this in a textbox that contains properly spelled words and it works fine. No worries here but strange nonetheless.

    Question:

    Can I fire the spellcheck as part of the option group click event? So in effect the function could complete before the recordsource for the subform is changed. If this might work, how would I pass ctlSpell (the active control prior to clicking the option group) back to the function when the option group has already been clicked? Perhaps there is a better way but my limited knowledge of Access is tapped at the moment.

    Thanks for looking and for providing any assistance you can.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    1. You can Declare a Global Object Variable as Type Control in a Standard Code Module, as in:
      Code:
      Public gctlActiveControl As Control
    2. At some point prior to the Option Group Click, assign the Object Variable to the appropriate Control, as in:
      Code:
      Set gctlActiveControl = Me![txtTest]
    3. You can then use the With...End With Structure in the traditional manner, as in:
      Code:
      With gctlActiveControl
        .SetFocus
        'YaDa-YaDa
      End With

    Comment

    • tuxalot
      New Member
      • Feb 2009
      • 200

      #3
      Thanks for the quick response ADezii. One thing I failed to note is the textbox I wish to spell check resides in a continuous subform, so I think that means that there is only one textbox. I'll give your code a go.

      Thanks again.

      Comment

      • tuxalot
        New Member
        • Feb 2009
        • 200

        #4
        This seems to work in the on click event of the option group:
        Code:
            sfrmResponses.SetFocus
            DoCmd.SetWarnings False
            DoCmd.RunCommand acCmdSpelling
            DoCmd.SetWarnings True
            Me.sfrmResponses.Form.RecordSource = "qsfrmSurveyResponses"
            Me.TabCtl.Value = 1
        I think I was overthinking it. I think.
        Last edited by tuxalot; Nov 23 '10, 05:01 AM. Reason: working now

        Comment

        Working...