Loop thru fields and then spell check?

andrewf10

Registered User.
Local time
Today, 15:42
Joined
Mar 2, 2003
Messages
114
I have 15 fields beginning with the word Comment. (i.e. comment, comment1, comment2 etc)


What Im trying to do is create a spellcheck command button that will only check these fields and only on the current record.

I've managed to find this piece of code to do the actual check:


With Me.FIELDNAME
.SetFocus
.SelStart = 0
.SelLength = Len(Me.FIELDNAME)
End With
DoCmd.RunCommand acCmdSpelling



Question is, how do I get this piece of code to loop through any field beginning with the word 'comment' and check their spelling?!

Any help would be much appreciated
 
Last edited:
I was working on the code when it occurred to me: why aren't you checking this in the BeforUpdate event of your controls? The code you posted is checking a control on your form and not a field in a record.
 
Last edited:
Have to ask why you have 15 comment fields?
 
Have to ask why you have 15 comment fields?

Because a returned job card can have up to 15 comments. Each of these comments is then assigned to a different person and has a corresponding status box. This allows them to report by any conbination.


Why aren't you checking this in the BeforUpdate event of your controls? The code you posted is checking a control on your form and not a field in a record.

Suppose I could put it in the AfterUpdate event of each textbox. Just thought there might a way of doing everything from one command button which would be more efficient.
 
I said the BeforeUpdate event of the controls and no extra button pushes required. The spelling check would take place automatically before any data is written to the table.
 
andrewf10 said:
Because a returned job card can have up to 15 comments. Each of these comments is then assigned to a different person and has a corresponding status box. This allows them to report by any conbination.
.

You don't need 15 separate fields to record 15 separate comments, two or maybe three fields will do the same.

Be very careful about running spell check on records that you may or may not wish to save, spell check will force a save
 
Finally got it to work. Here it is:



Private Sub SpellcheckComments_Click()

Dim ctl As Control
For Each ctl In Forms!JobCards!Tab2.Controls 'Comment: Go to Tab 2

'Comment: Loop through all textboxes except the two below. Also ignore blank fields

If (ctl.ControlType = acTextBox) And (ctl.Name <> "Schedule No1" And ctl.Name <> "Job Number1") And IsNull(ctl) = False Then
DoCmd.SetWarnings False 'Comment: Hide Access standard messages
With ctl
.SetFocus
.SelStart = 0
.SelLength = Len(ctl)
End With
DoCmd.RunCommand acCmdSpelling

End If
Next ctl
DoCmd.SetWarnings True 'Comment: Unhide Access standard messages for other events
MsgBox "The spellcheck is now complete for all comments.", vbInformation, "Spelling complete"
End Sub
 
Hi andrewf10,

Thanks for posting back with your solution.
 

Users who are viewing this thread

Back
Top Bottom