How To Add A Spellchecker To An Access Database Form

When entering data one can occasionally misspell a word or two. We are all used to having a spell checker at hand when typing a Word document for instance.

Why should a spell check be limited to Word documents? Surely it would be of benefit if we could incorporate something similar in an Access database.

Well, I have some good news. We can do exactly that!

Create a form with a text box or memo field.

Enter some text into either of these controls.

Create a command button on your form.

Go into the properties of the button and set the caption to be ‘Spell Check’.

Right click the command button and select ‘Build event’.

Between the Private Sub and the End Sub enter the following code

You can copy and paste it if you like

With Me![My control name]
If Len(.Value) > 0 Then
DoCmd.SetWarnings False
.SetFocus
.SelStart = 1
.SelLength = Len(.Value)
DoCmd.RunCommand acCmdSpelling
.SelLength = 0
DoCmd.SetWarnings True
End If
End With

Replace the words inside the square brackets [My control name] with the name of your own control that you want to spell check.

Save the code and close the code window.

Now run your form and click the button.

Enter some misspelled text in your control and then click the spell check button.

You will find you get a similar spelling suggestion box that you have seen many times before when writing Word documents.

Let’s look at what’s actually happening in this code.

Don’t worry too much about understanding it – I will cover programming in further tutorials. This will give you a general idea though.

I want you to spell check this control

With Me![My control name]

If there is something in that control then go ahead and spell check it

If Len(.Value) > 0  Then

Turn all warning messages off for now

DoCmd.SetWarnings False

Focus to the control I want to spell check

.SetFocus

Start at the first character

.SelStart = 1

And continue to the last character of the word

.SelLength = Len(.Value)

Now run the spell check

DoCmd.RunCommand acCmdSpelling

Clear the variable used for the length of the word ready for the next spell check

.SelLength = 0

Turn all warning messages back on

DoCmd.SetWarnings True

Tags: , , ,