Results 1 to 13 of 13
  1. #1
    warren0127 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    69

    Implementing a Spell Check for an entire Form (multiple fields)

    Hi all.

    I have figured out how to implement a spell check for a specific single "field" - but I wish to have a spell checker for all of my fields within a form.

    Right now I am using the following VBA code with a spellchecker button that performs a spellcheck on one field called "Purpose":

    Private Sub Spellcheck_Click()

    With Me!Purpose

    Me!Purpose.SetFocus

    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



    Any suggestions on how to do this on multiple fields at once within the same form would be much appreciated.

    Thank you.

    - Warren

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    You can iterate all the controls in the Form's collection. If you isolate the type by say actextbox, you can run your spellcheck code on those controls.

    Maybe something like

    Code:
    dim ctl as control
    
    for each ctl in me.controls
    
    if ctl.type = acTextBox
    ...
    'do something
    
    next ctl
    
    end if
    https://msdn.microsoft.com/en-us/lib.../ff194205.aspx

    .

  3. #3
    warren0127 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    69
    Thank you for your response.

    Not entirely sure I am doing this correctly. Should I be using your example code in conjunction with my current existing code for the button, or do I need to make something run for the entire form without the need to use a button?

    Thanks
    - Warren

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Well, the code I provided is just an idea. It is not functioning code. I just typed out some stuff off of the top of my head and placed an ellipses where your spellcheck thing would go.

    You could probably replace the ellipses with the code you have there and get some sort of result.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Here's something I did years ago...It's the same basic code you already have, but uses the method ItsMe described to loop through all Textboxes on the Form. In a Standard Module, enter this code:

    Code:
    Public Function SpellChecker()
    
    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 Len(ctrl) > 0 Then
         With ctrl
          .SetFocus
          .SelStart = 0
          .SelLength = Len(ctrl)
         End With
         
         DoCmd.RunCommand acCmdSpelling
           
       End If
     End If
    
    Next
    
    DoCmd.SetWarnings True
    
    End Function


    Then, behind your Command Button use the code

    Code:
    Call SpellChecker


    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    warren0127 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    69
    ItsMe + Missinglinq - thanks for your reply.

    Missinglinq - I went ahead and messed around with the above example and it works. But I have another dilemma.. I am using subforms in tabbed controls within a main form. So.. I have one overall form, with 5 subforms embedded.

    The code runs just in the main form perfect.. but the problem is, it does not run the spell checker within the subforms. I put the code separately/individually in each of the subforms and still does not seem to work. When I click the spell check button, it jumps back to the main form automatically and skips the actual subform I am trying to run the spellcheck.

    I tried to mess around with the VBA to get it to work for the subforms in the tabbed controls, but cannot seem to get around this. Any idea what I am missing?

    I tried to add "Dim subfrm as Subform" but can't seem to figure it out.

    Thanks
    - Warren
    Last edited by warren0127; 01-04-2016 at 03:09 PM.

  7. #7
    warren0127 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    69
    Apologize for the double post - but for running the spellcheck function in a subform that is embedded in a main form, is there something specific I have to include? I tried including the control for the subform and still does not work.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I am not sure which code you are using. However, if you are using the code in post #5, you will want to adjust the following line to recognize the subform container name.
    Set frm = Screen.ActiveForm

    So for the subform, you will want something like the following ...
    Set frm = Forms!MainFormName!SubFormControlName!Form
    or maybe
    Set frm = Me.SubFormControlName!Form

  9. #9
    warren0127 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    69
    Within the main form, I currently have the following code in place:

    Code:
    Public Function SpellChecker()
    
    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 Len(ctrl) > 0 Then
         With ctrl
          .SetFocus
          .SelStart = 0
          .SelLength = Len(ctrl)
         End With
         
         DoCmd.RunCommand acCmdSpelling
           
       End If
     End If
    
    Next
    
    DoCmd.SetWarnings True
    
    End Function
    
    Private Sub Spellcheck_Click()
    
    Call SpellChecker
    
    End Sub

    I also added the same code in my other forms, which are "subform" controls in the Main form. However, after I tried entering stuff like Forms!MainFormName!SubFormControlName!Form - it gave me errors. I have to figure out a way to change the focus and have it spellcheck the actual subform -- but do I place the code in the main form VBA, or do I put the code in the actual forms. I'm thinking since I am working off of the main form, and it has the other forms as "subform controls" -- everything should technically be in the main form code since the subforms are controls.

    I'm still not able to get it to work.. i'll keep trying - thanks for your help

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Unfortunately, the answer to where the function belongs is not straight forward. Since it is a Public Function, you can place that code just about anywhere. A more appropriate question might be, "Where do I call the function from?" So, you could place the function in your main form and it would probably be a good idea to call the code from the main form in a click event for a command button.

    If you want to do a spellcheck on a subform, you will need to provide the correct name, as described in one of my previous posts. You will have to determine what the names are. I do not know what they are. You can use the property sheet and look the name property for the various objects. Replace the appropriate parts in my example with the actual names.
    Forms!MainFormName!SubFormControlName!Form

  11. #11
    warren0127 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    69
    Hi ItsMe,

    I had used the actual form and control names as you indicated I should be doing above. The issue I am facing is that on the main form, I have a spellchecker in place to spellcheck the main form. Then, I have multiple tabs on the mainform (tabbed controls), each tab has a subform. So, if I'm calling the function on the mainform to perform the spellcheck on a subform, will I need to have two public functions for the spellchecker? One to perform the spellchecker on the mainform, and one for the subform(s)? Because right now, The mainform spellchecker works fine -- but I am not sure if I can modify the spellcheck function to do a spellcheck for both the main form ( Set frm = Screen.ActiveForm ) and the subform ( Set frm = !Forms!frmProgram!subformcontrol!Form ) or how to create multiple spellcheck functions?

    Here is an example:

    Code:
    Public Function SpellChecker()
    
    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 Len(ctrl) > 0 Then
         With ctrl
          .SetFocus
          .SelStart = 0
          .SelLength = Len(ctrl)
         End With
         
         DoCmd.RunCommand acCmdSpelling
           
       End If
     End If
    
    Next
    
    DoCmd.SetWarnings True
    
    End Function
    
    
    ///////////////////// This button calls the spellcheck on the mainform - works fine //////////////////
    
    Private Sub Spellcheck_Click()
    
    Call SpellChecker
    
    End Sub
    
    
    //////////////// The button below would call the spellcheck to perform a spellcheck on the subform ////////////////
    
    Private Sub Command76_Click()
    
    Call SpellChecker
    
    End Sub
    
    //////////////// The below function is for the subform - but how can I include this when I already have a function for the mainform? //////////////
    
    Public Function SpellChecker()
    
    Dim ctrl As Control
    
    Dim frm As Form
    
    Set frm = Forms!MainForm!SubFormControl!Form
    
    DoCmd.SetWarnings False
    
    For Each ctrl In frm.Controls
     
     If TypeOf ctrl Is TextBox Then
       If Len(ctrl) > 0 Then
         With ctrl
          .SetFocus
          .SelStart = 0
          .SelLength = Len(ctrl)
         End With
         
         DoCmd.RunCommand acCmdSpelling
           
       End If
     End If
    
    Next
    
    DoCmd.SetWarnings True
    
    End Function
    Thanks
    - Warren

  12. #12
    warren0127 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    69
    Sorry for the double post. I created another public function called "Spellchecker2" and the button for the subform spellcheck calls it.

    So, with adding the
    Code:
     Set frm = Forms!frmTabbedProject!frmProductQueryControl!Form
    within the function, I get the following error:

    "Run-time error '2465':

    Microsoft Access can't find the field 'Form' referred to in your expression"

  13. #13
    warren0127 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    69
    I finally figured out what was wrong with my code. I realized that instead of replacing Set frm = Screen.ActiveForm with:

    Forms!MainFormName!SubFormControlName!Form

    That I need to use:

    Forms!MainFormName!SubFormControlName.Form

    So I needed to change the "!" to a "."

    Now, I can run a spellcheck on all subforms individually from the main form.

    Thanks for your help

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-12-2014, 07:42 AM
  2. trying to turn off spell check for sent emails
    By trevor40 in forum Programming
    Replies: 2
    Last Post: 02-13-2014, 08:05 PM
  3. Spell and grammar check
    By destroyer in forum Forms
    Replies: 1
    Last Post: 01-19-2014, 11:51 AM
  4. Suppress spell check error message
    By sabre1 in forum Forms
    Replies: 1
    Last Post: 03-24-2011, 09:58 AM
  5. Code to spell out check amount?
    By spkoest in forum Access
    Replies: 4
    Last Post: 06-16-2009, 07:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums