Spell check entire tabbed form

I'm trying to figure out how to use a command button onclick event to spell check an entire Access tabbed form.  Does anyone have a solution?

I have tried this code but it gives me an error that reads:

"Databasename can't move the focus to the control txtExpirationDate"  The field is set to TabStop = No but I tried TabStop = Yes also and got the same message.

Private Sub cmdSpellCheck_Click()

    Dim i As Integer
    'Turning off warnings to prevent completion message after each control
    ' is checked
    DoCmd.SetWarnings False
    'Loop through each control on the form
    For i = 0 To Me.Count - 1
    'Check to see if the control is a textbox
    If TypeOf Me(i) Is TextBox Then
    'Verify that focus is set to the control
    Me(i).SetFocus
    'Select starting point and select the contents of the control
    Me(i).SelStart = 0
    'Verify that the control contains data and select the contents
    If Len(Me(i)) > 0 Then
    Me(i).SelLength = Len(Me(i))
    'Run the Spell Checker on the contents of the control
    RunCommand acCmdSpelling
    End If
    End If
    Next i
    'Tell user that the check is complete for this record.
    MsgBox "Spell Check is Complete"
    'Turning warnings back on
    DoCmd.SetWarnings True

End Sub

Open in new window

SteveL13Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbizupCommented:
Are all your controls unlocked, enabled and visible?  If not, you will have to add code to unhide and enable and/or unlock them temporarily before setting focus to them.
0
mbizupCommented:
Alternatively, if you have hidden or disabled textboxes whose values are set through code and DON'T need to be spell checked you can conditionally exclude them.
0
SteveL13Author Commented:
Regarding, "Alternatively, if you have hidden or disabled textboxes whose values are set through code and DON'T need to be spell checked you can conditionally exclude them. " how do I do that?
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

SteveL13Author Commented:
Now trying this:

Private Sub cmdSpellCheck_Click()

    Dim i As Integer
    Dim ctrl As Control
    DoCmd.SetWarnings False
    For i = 0 To Me.Count - 1
        If TypeOf Me(i) Is TextBox Then
            If ctrl.Tag = "Skip" Then
                ctrl.Locked = False
                Me(i).SetFocus
                Me(i).SelStart = 0
                If Len(Me(i)) > 0 Then
                    Me(i).SelLength = Len(Me(i))
                    RunCommand acCmdSpelling
                    ctrl.Locked = True
                End If
            End If
        End If
    Next i
    MsgBox "Spell Check is Complete"
    DoCmd.SetWarnings True

End Sub

Open in new window


But getting "Object variable or With block variable not set."
??
0
mbizupCommented:
That's because you haven't set your Object variable.   ;-)

In this case the Object Variable is Ctrl.  

To set it (this needs to happen before you use ctrl):

Set ctrl = Me(i)

Open in new window



For consistency, I'd use ctrl instead of Me(I) throughout this block of code, or use Me(I) instead of ctrl.  My own preference would be to use ctrl (it just looks cleaner).
0
SteveL13Author Commented:
I must have this thing totally botched up.  Here is what I have now.  Still getting "Object variable or With block variable not set."

Private Sub cmdSpellCheck_Click()

    Dim i As Integer
    Dim ctrl As Control

    DoCmd.SetWarnings False
    For i = 0 To Me.Count - 1

        Set ctrl = ctrl

        If TypeOf ctrl Is TextBox Then
            If ctrl.Tag = "Skip" Then
                ctrl.Locked = False
                ctrl.SetFocus
                ctrl.SelStart = 0
                If Len(ctrl) > 0 Then
                    ctrl.SelLength = Len(ctrl)
                    RunCommand acCmdSpelling
                    ctrl.Locked = True
                End If
            End If
        End If
    Next i
    MsgBox "Spell Check is Complete"
    DoCmd.SetWarnings True

End Sub

Open in new window

0
SteveL13Author Commented:
Ok.  Can't say I haven't tried.  Here's where I'm at.  But I intentionally misspelled a word and it didn't catch it.  I have set the tag to Skip in several fields but not the one I misspelled.


    Dim ctrl As Control
    Dim frm As Form

    Set frm = Screen.ActiveForm

    DoCmd.SetWarnings False

    For Each ctrl In frm.Controls

        If TypeOf ctrl Is TextBox Then

            If ctrl.Tag = "Skip" Then

                If Len(ctrl) > 0 Then
                    With ctrl
                        .SetFocus
                        .SelStart = 0
                        .SelLength = Len(ctrl)
                    End With
                    DoCmd.RunCommand acCmdSpelling
                End If

            End If
            
        End If

    Next

    DoCmd.SetWarnings True
    
    MsgBox "This estimate has been spell checked."

Open in new window

0
mbizupCommented:
You're very close...

The only problem is that your "If" block is only running the spell check when the tag property is "Skip", so the logic and functionality is opposite of what it should be.


You just need to change the If statement so that the check runs if the tag property is NOT "Skip", like this:

            If ctrl.Tag <> "Skip" Then
                  'etc
 

Open in new window



(I made that single change to your code, and it seemed to work as expected.)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteveL13Author Commented:
Here is what  I ended up with so far.  Please note that I had to comment two of the lines out to make it work.

    Dim ctrl As Control
    Dim frm As Form
    Dim frmtab As TabControl
  
    Set frm = Screen.ActiveForm

    DoCmd.SetWarnings False

    For Each ctrl In frm.Controls
       If TypeOf ctrl Is TextBox Then
            If ctrl.Tag <> "Skip" Then
                If Len(ctrl) > 0 Then
                    With ctrl
                        Debug.Print .Name
                        intCount = intCount + 1
'                        .SetFocus
'                        .SelStart = 0
'                        .SelLength = Len(ctrl)
                    End With
                    DoCmd.RunCommand acCmdSpelling
                End If
            End If
        End If
    Next

    DoCmd.SetWarnings True
    MsgBox "This estimate has been spell checked."

Open in new window

0
SteveL13Author Commented:
Sorry.  THREE lines were commented out.
0
mbizupCommented:
Are you good to go then?
0
SteveL13Author Commented:
Yes.  It seems to be working correctly.  I will award points to you in a few minutes.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.