Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2004
    Location
    Tampa, FL
    Posts
    520

    Unanswered: Spell checking a field

    I have this code I gleaned from the net.

    Code:
    Private Sub txtnote_AfterUpdate()
    
    'If the textbox contains data run the
    'Spell Checker after data is entered.
        If Len(Me!txtnote & "") > 0 Then
            DoCmd.RunCommand acCmdSpelling
                Else
            Exit Sub
        End If
    End Sub
    Is there a way to constrain the spell check to just the text entry box in question?
    Last edited by Darasen; 11-15-04 at 16:59.
    Darasen

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Well...Since you asked and it looks like no one else is going bite on this...off hand, you can try this little method.


    First: Place the following function into a database code module:

    Code:
    'Function For Spell-Checking a Form or SubForm Field.
    'The WinWord Dictionary is used for this.
    Public Function SpellCheck(SpellCheckField)
    	Dim Xobj As Object
    	SpellCheckField.SetFocus
    	Set Xobj = CreateObject("Word.Application")
    	Xobj.Visible = False: DoEvents
    	Xobj.Documents.Add
    	Xobj.Selection.Text = SpellCheckField.Text
    	Xobj.ActiveDocument.CheckSpelling
    	SpellCheckField.Text = Xobj.Selection.Text
    	Xobj.ActiveDocument.Close savechanges:=0
    	Xobj.Quit: DoEvents
    	Set Xobj = Nothing
    End Function
    Second: Enter the following directly into the On Lost Focus event line for your TextBox field:

    =SpellCheck([myTextBoxNameOnForm])

    You can do this with any TextBox control on your form. Keep in mind though, it may pause setting focus to the next form field simply because the dictionary is checking the field whether there are spell errors or not. Play with the code a while and tweak it to suit your needs.

    This sample uses the WinWord dictionary.


  3. #3
    Join Date
    Sep 2004
    Location
    Tampa, FL
    Posts
    520
    Thanks for the reply that almost works wonders.
    It had 1 small error.
    Code:
    SpellCheckField.SetFocus
    This line prevented me from ever exiting the txtbox in question as it kept resetting the focus to the field I was trying to exit.

    I wil now see if I can get it to NOT run if the field is empty.

    Thanks again.
    Darasen

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    If you are having problems with the SpellCheckField.SetFocus then remove it from the code.

    To ignore the the field in question if it is empty, then add this to the function code:

    Code:
    Public Function SpellCheck(SpellCheckField)
       If Not IsNull(SpellCheckField) Or Len(SpellCheckField) > 0 Then
    	  Dim Xobj As Object
    	  Set Xobj = CreateObject("Word.Application")
    	  Xobj.Visible = False: DoEvents
    	  Xobj.Documents.Add
    	  Xobj.Selection.Text = SpellCheckField.Text
    	  Xobj.ActiveDocument.CheckSpelling
    	  SpellCheckField.Text = Xobj.Selection.Text
    	  Xobj.ActiveDocument.Close savechanges:=0
    	  Xobj.Quit: DoEvents
    	  Set Xobj = Nothing
       End If
    End Function

  5. #5
    Join Date
    Dec 2004
    Posts
    4

    Using button to spell check

    Do you know how to modify the code so a user can press a button to do the spell check?

    This code works great for the lost focus command.

  6. #6
    Join Date
    Sep 2004
    Location
    Raleigh, NC
    Posts
    146
    Quote Originally Posted by bluecloud
    Do you know how to modify the code so a user can press a button to do the spell check?

    This code works great for the lost focus command.
    I use the following code for command buttons.. Give it a try..

    Code:
    Private Sub cmdButton1_Click()
        If Len(Me!Text1 & "") > 0 Then
            With Me!Text1
                .SetFocus
                .SelStart = 0
                .SelLength = Len(Me!Text1)
            End With
            DoCmd.SetWarnings False
            DoCmd.RunCommand acCmdSpelling
            DoCmd.SetWarnings True
        End If
    End Sub

  7. #7
    Join Date
    Dec 2004
    Posts
    4

    Smile

    smacdonaldnc, Awesome...that worked!

    Thanks.

  8. #8
    Join Date
    May 2005
    Posts
    1,191
    Sorry to reserrect an old thread, but I get the attached error when trying to run smacdonaldnc 's code.

    I checked out Microsoft's website to try to figure it out, but I couldn't get anything from that.

    Can anyone help me here? As always, any help would be appreciated.
    Attached Thumbnails Attached Thumbnails Error.jpg  
    Me.Geek = True

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •