I have a subform in datasheet view. I would like to put a button on the mainfor that checks all the subform records for spelling mistakes. Is this possible?
Dim i As Integer
'Turning off warnings to prevent completion message after each control
' is checked
DoCmd.SetWarnings False
'Loop through each control on the form
For i = 0 To Me.Count - 1
'Check to see if the control is a textbox
If TypeOf Me(i) Is TextBox Then
'Verify that focus is set to the control
Me(i).SetFocus
'Select starting point and select the contents of the control
Me(i).SelStart = 0
'Verify that the control contains data and select the contents
If Len(Me(i)) > 0 Then
Me(i).SelLength = Len(Me(i))
'Run the Spell Checker on the contents of the control
RunCommand acCmdSpelling
End If
End If
Next i
'Tell user that the check is complete for this record.
MsgBox "Spell Check is Complete"
'Turning warnings back on
DoCmd.SetWarnings True
======================================
This will spellcheck in only one control..
Private Sub cmdSpell_Click()
'One control only
On Error Resume Next
Dim ctlSpell As Control
' Check the spelling in the selected text box
Set ctlSpell = Screen.PreviousControl
If TypeOf ctlSpell Is TextBox Then
If IsNull(Len(ctlSpell)) Or Len(ctlSpell) = 0 Then
MsgBox "There is nothing to spell check."
ctlSpell.SetFocus
Exit Sub
End If
With ctlSpell
.SetFocus
.SelStart = 0
.SelLength = Len(ctlSpell)
End With
DoCmd.RunCommand acCmdSpelling
Else
MsgBox "Spell check is not available for this
item."
End If
I tried the code. because it runs through all the controls i get the following error
Run Time Error '2110':
Log Cert Entry cant move the focus to the control AirframeEntryID.
Log Cert Entry being the name of my db and the AirframeEntryID the name of the control. AirframeentryID is a hidden control and is NOT enabled. I also moved it to the last item in the tabbing order.
When debugging the code it focused on the following line.
when using the spellcheck for a single control, it wont allow you to use it on the subform (datasheet). Saying cannot "Spell check is not available for this
item." being that it only checks to see if the control is a text box.