Spell check of form and subform

D

dsc2bjn

I am trying to spell check a form and a subform and have adapted some code to
run the spell check when the type of control is a textbox. This works well
in the form; however, in the subform I do not have any textboxes. The
control is a memo field.

I would like to be able to spell check the subform memo box before the user
is allowed to navigate back to the form.


I tried using the following code in the subform, but recieve a message
stating "Object or with variable not set".


Private Sub Form_AfterUpdate()

On Error GoTo Err_form_AfterUpdate
Dim intIsError As Integer

intIsError = 0

If (Eval("[Forms]![frmOther Weakness Corrective Actions (New Entry)]![Other
Corrective Action Plan subform1]![CorrectiveActionPlanItem] Is not Null and
[Forms]![frmOther Weakness Corrective Actions (New Entry)]![Other Corrective
Action Plan subform1]![OCD] Is Null")) Then
MsgBox "A Value for 'Corrective Action Estimated Completion Date' is
Required.", vbOKOnly, "Required Value Missing"
intIsError = 1
End If

If intIsError = 0 Then

Dim sf_ctlSpell As Control
Dim sf_frm As SubForm

If TypeOf sf_ctlSpell Is SubForm Then
Set sf_frm = Screen.ActiveForm

DoCmd.SetWarnings False

For Each sf_ctlSpell In sf_frm.Controls

If sf_ctlSpell Is CorrectiveActionPlanItem Then

If Len(sf_ctlSpell) > 0 Then

With sf_ctlSpell

If .Tag = "True" Then

.SetFocus
.SelStart = 0
.SelLength = Len(sf_ctlSpell)

DoCmd.RunCommand acCmdSpelling

End If

End With

End If

End If


Next

' MsgBox "Spell check complete.", vbInformation + vbOKOnly, "Finished."
DoCmd.SetWarnings True
DoCmd.Close
End If
End If
Exit_AfterUpdate:

Exit Sub

Err_form_AfterUpdate:
MsgBox Err.Description
Resume Exit_AfterUpdate

End Sub


I just can't seem to find the error.

What did I do wrong?
 
A

Alex Dybenko

Hi,
first - try to debug your code to see what actually happens.
then try to set focus to subform and then set reference to form as:

Set sf_frm = me!SubfornName.form

where SubfornName is a name of subform contol

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com
 

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

Top