Spell Check a Record

G

Guest

How do you set a form to spell check a "record" only, without continuing to
check the entire database? I want to create a function that checks spelling
after a user enters data in a field (before they exit the record).
 
G

Guest

Hi WolfPack,

Here is a function that was previously posted by Access MVP Arvin Meyer. If
you place this into a module, you can call it from any form:

Option Compare Database
Option Explicit

Public Function Spell()
' Arvin Meyer 9/17/1998
' Adapted from code by Terry Wickenden
Dim ctlSpell As Control
Dim frm As Form
Set frm = Screen.ActiveForm
DoCmd.SetWarnings False
' Enumerate Controls collection.
For Each ctlSpell In frm.Controls
If TypeOf ctlSpell Is TextBox Then
If Len(ctlSpell) > 0 Then
With ctlSpell
.SetFocus
.SelStart = 0
.SelLength = Len(ctlSpell)
End With
DoCmd.RunCommand acCmdSpelling
End If
End If
Next

DoCmd.SetWarnings True
End Function


You can call the Spell function from a command button on a form. For example:

Private Sub cmdSpellCheck_Click()
On Error GoTo ProcError

Call Spell

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, , _
"Error in cmdSpellCheck_Click event procedure..."
Resume ExitProc
End Sub


You could also call it automatically, by using the Form's AfterUpdate event
procedure:

Private Sub Form_AfterUpdate()
On Error GoTo ProcError

Call Spell

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in Form_AfterUpdate procedure..."
Resume ExitProc
End Sub


However, in this case, it will only be called if you dirty a record by
editing it. My only suggestion to the function, as given, is that you might
want to add error handling and ensure that warnings are turned back on even
if the function does not run to completion for any reason. For example:

Public Function Spell()
On Error GoTo ProcError

<rest of code goes here, except move the statement to turn warnings back on
to the ProcError label, as indicated below>

ExitProc:
DoCmd.SetWarnings True
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Spell..."
Resume ExitProc
End Function


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

:

How do you set a form to spell check a "record" only, without continuing to
check the entire database? I want to create a function that checks spelling
after a user enters data in a field (before they exit the record).
 
G

Guest

Next question...

How do I focus on spell checking a specific field, not the whole form?
 
G

Guest

Hi WolfPack,

You don't enumerate the controls collection. In this case, if you want to
still allow this function to be called from any form, you could modify the
function to accept a parameter (ctl As Control). You can call the modified
function like this, from the click event procedure of a command button or the
form's AfterUpdate event procedure, as before:

Call Spell(txtDescription)

where txtDescription is the name of the textbox that you wish to spell
check. Change this to the name of the textbox that applies in your case. Here
is the modified Spell function:

Option Compare Database
Option Explicit

Public Function Spell(ctlSpell As Control)
On Error GoTo ProcError
' Modified by Tom Wickerath 1/17/2006 to limit spell
' checking to one control on the form.

' Arvin Meyer 9/17/1998
' Adapted from code by Terry Wickenden
'Dim ctlSpell As Control
Dim frm As Form
Set frm = Screen.ActiveForm
DoCmd.SetWarnings False
' Enumerate Controls collection.
' For Each ctlSpell In frm.Controls
' If TypeOf ctlSpell Is TextBox Then
If Len(ctlSpell) > 0 Then
With ctlSpell
.SetFocus
.SelStart = 0
.SelLength = Len(ctlSpell)
End With
DoCmd.RunCommand acCmdSpelling
End If
' End If
' Next

ExitProc:
DoCmd.SetWarnings True
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Spell..."
Resume ExitProc
End Function


Note: If you are calling this function from code, as I have shown in all
examples (ie. Form_AfterUpdate or command button click event), then you can
change this function to a subroutine, since it is not returning a value. In
that case, you'd also change the Exit Function and End Function lines to Exit
Sub and End Sub, respectively.


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

:

Next question...

How do I focus on spell checking a specific field, not the whole form?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top