Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Spell check code
Garry Smith 
    
2 years ago
I am trying to create a generic Spell Check function or sub that will work from a button on the parent form that will also work when clicked from any sub form.
but errors on the subform

The code:
DetailsPublic Sub RunSpellCheckForTextbox(txtBoxName As String)
    ' Run spell check for the specified textbox control
    ' Assumes that the textbox control is on the active form or its subforms
    
    Dim frm As Form
    Dim ctl As Control
    Dim subformCtl As SubForm

    On Error Resume Next
    Set ctl = Screen.ActiveControl
    On Error GoTo 0

    If Not ctl Is Nothing Then
        ' Check if the control is a subform control
        If TypeOf ctl Is SubForm Then
            Set subformCtl = ctl
            Set frm = subformCtl.Form
        Else
            Set frm = ctl.Parent
        End If

        On Error Resume Next
        Set ctl = frm.Controls(txtBoxName)
        On Error GoTo 0

        If Not ctl Is Nothing Then
            ctl.SetFocus
            ctl.SelStart = 0
            ctl.SelLength = Len(ctl.Value)
            DoCmd.RunCommand acCmdSpelling
        Else
            MsgBox "Textbox control '" & txtBoxName & "' not found on the active form or its subforms.", vbExclamation, "Error"
        End If
    Else
        MsgBox "No active control found. Please ensure you are on the correct form or subform.", vbExclamation, "Error"
    End If
End Sub


Execution on the buttons OnClick event:
RunSpellCheckForTextbox Screen.PreviousControl.Name

The Error:
| Run-time error '438':
| Object doesn't support this property or method

DetailsIf Not ctl Is Nothing Then
ctl.SetFocus

Debugger line >>> ctl.SelStart = 0

ctl.SelLength = Len (ctl. Value)
DoCmd. RunCommand acCmdSpelling

Else


Any help would be appreciated
Sami Shamma  @Reply  
             
2 years ago
I have such function in my code that works. I will share it with you once I get to the office later today.
Garry Smith OP  @Reply  
    
2 years ago
Thank you Sami.
Sami Shamma  @Reply  
             
2 years ago
to use it:

DetailsPrivate Sub SpellCheckBtn_Click()
    
    CheckSpelling Narrative
    CheckSpelling AssociateNarrative

End Sub



The Sub code :

DetailsPublic Sub CheckSpelling(C As Control)
    
    If IsNull(C) Then Exit Sub
    
    DoCmd.SetWarnings False
    C.SetFocus
    C.SelStart = 0
    C.SelLength = Len(C)
    DoCmd.RunCommand acCmdSpelling
    DoCmd.SetWarnings True
    
End Sub

Garry Smith OP  @Reply  
    
2 years ago
Thanks again Sami,
Please explain

    CheckSpelling Narrative
    CheckSpelling AssociateNarrative
Adam Schwanz  @Reply  
           
2 years ago
If you look at Samis code for the CheckSpelling function, you'll see (C As Control) that you're sending to it. It's basically the field name of the control you want to spell check.

CheckSpelling MyFieldName
Sami Shamma  @Reply  
             
2 years ago
As @Adam explained,

Narrative & AssociateNarrative are fields on the form that I want to spellcheck
Garry Smith OP  @Reply  
    
2 years ago
Thanks for the code, Sami. This is very Similar to the code that I have been using in my applications for some time. I use Screen.PreviousControl to satisfy the parameter. This works for the current form, but the code needs to be included in all of the embedded Forms and Continuous Forms. As I indicated above, I was trying to accomplish just having one button on the parent form that would apply the spell check to whatever embedded form the user was on when the Spell Check button was clicked. I have some forms that use the Tab Control to list multiple subforms and seems redunddant to have a button on each form for the same purpose which is why I posted the code that I was trying to get to work.
Sami Shamma  @Reply  
             
2 years ago
Requery Subform
Value From a Form

use:



Forms!FName!Subform.Form!Field to refer to the subform field.
Adam Schwanz  @Reply  
           
2 years ago
You can use this kind of code to interact with all the subforms as well
    Dim C As Control
    For Each C In Me
        If TypeOf C Is SubForm Then
         MsgBox C.Name
        End If
    Next
Chris Pardy  @Reply  
   
2 years ago
is it possible to have this run from the after update event of a field do the user doesn't have to click anything ?  I've tried but get errors.
Sami Shamma  @Reply  
             
2 years ago
Try in the Form not the Field "After Update"
Chris Pardy  @Reply  
   
2 years ago
This prevents the record from committing
Sami Shamma  @Reply  
             
2 years ago
Is this a question or a statement?
After Update: Record committed to the table and cannot be cancelled.
Before Update: Record completed but not yet committed to the table and can be cancelled.
Chris Pardy  @Reply  
   
2 years ago
apologies... Placing the script in the after update of the form, it did trigger the spellcheck, but then the record wont commit and stays dirty..actually it locks up the form and I have to close the form without saving. I did try it in the before update as well and it had the same result.
Richard Rost  @Reply  
           
2 years ago
You're honestly better off with a spellcheck BUTTON to handle this. Events that need to wait and continue can be a nightmare... unless you open a spellcheck form as a DIALOG form where it can have the database WAIT until you're done with it to continue your code. See Custom Date Picker.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 9:23:24 PM. PLT: 1s