Running spell check on a field

J

John

Hi

How can I run spell check on a field on a form by the press of a button?

Many Thanks

Regards
 
L

Larry Daugherty

In the OnClick event of your command button put:

DoCmd.RunCommand acCmdSpelling

Remember to include your error handling code.

HTH
 
T

Tom Wickerath

Hi John,

How about something like this (two text box controls shown in this example):

Private Sub cmdSpellCheck_Click()
On Error GoTo ProcError

SpellCheck ("txtRequestTitle")
SpellCheck ("txtRequestDescription")

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


Add the following code to a new module, so that it can be called from any
form. Name the new module something like basUtilities (or anything except the
name of this procedure [SpellCheck] or any other existing procedures in your
database):

Private Sub SpellCheck(strControlName As String)
On Error GoTo ProcError

DoCmd.SetWarnings False
Dim ctl As Control

Set ctl = Controls(strControlName)
With ctl
If Len(.Text) > 0 Then
.SelStart = 0: .SelLength = Len(.Text)
DoCmd.RunCommand acCmdSpelling
End If
End With

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




Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
J

John

Hi

Giving me an 'Sub or Function not defined' error on function Controls in
line; Set ctl = Controls(strControlName)

What am I doing wrong?

Thanks

Regards

Tom Wickerath said:
Hi John,

How about something like this (two text box controls shown in this
example):

Private Sub cmdSpellCheck_Click()
On Error GoTo ProcError

SpellCheck ("txtRequestTitle")
SpellCheck ("txtRequestDescription")

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


Add the following code to a new module, so that it can be called from any
form. Name the new module something like basUtilities (or anything except
the
name of this procedure [SpellCheck] or any other existing procedures in
your
database):

Private Sub SpellCheck(strControlName As String)
On Error GoTo ProcError

DoCmd.SetWarnings False
Dim ctl As Control

Set ctl = Controls(strControlName)
With ctl
If Len(.Text) > 0 Then
.SelStart = 0: .SelLength = Len(.Text)
DoCmd.RunCommand acCmdSpelling
End If
End With

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




Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

John said:
Hi

How can I run spell check on a field on a form by the press of a button?

Many Thanks

Regards
 
T

Tom Wickerath

Mea culpa!

I see that the procedure I provided, Private Sub SpellCheck, was not in a
stand-alone module after all. It was in the same class module associated with
the form with the Private Sub cmdSpellCheck_Click() procedure. In the same
database, I did have a public spell checking function, but this one does not
accept any parameters. For some reason, I wasn't even using that one. I don't
remember why I did this at the moment.

So, try moving this procedure to the class module associated with the same
form. Alternatively, you can try this version in the stand-alone module, but
it is going to spell check every text box on your form:

Public Function Spell()
On Error GoTo ProcError

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


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
J

Jacob

How do you stop it at the current record? I have spell check on my
funciton, but it wants to cycle back through all the entries to check the
spelling. how can you stop it at the current record???


Jacob
 
J

Jacob

Hi Tom, here is the code behind the button. I have a memo box where data can
be typed in to it. It is located on a form that is directly linked to the
table. The problem is, when I hit spell check, it trys to go back through
all the records and spell check.

Private Sub sc_Click()

Me.Entry.SetFocus
DoCmd.RunCommand acCmdSpelling

End Sub
 
J

John Spencer

Try this modification to your code. Selecting all the text or any
portion of the text will limit the spell check to the selected text.

Private Sub sc_Click()

Me.Entry.SetFocus
Me.Entry.SelStart = 0
Me.Entry.SelLength = Len(Me.Entry)
DoCmd.RunCommand acCmdSpelling

End Sub


'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 

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