How to spell check sub-form controls from a form?

G

Guest

MS Access 2K, Windows XP
====================
Hi,

I'm trying to spell check the textbox and memo controls on a form and a
subform. Thanks to Arvin Meyer's code, I'm able to spell-check the controls
on the form.

But, is there a way to spell-check the controls on a subform? I only have
one subform on a form (meaning one level down) and no nested subforms within
a subform.

I modified the code but I'm getting an "Application defined or
object-defined error" when I run the code.

I have a button on the form that calls this function which is defined in a
module. I'm quite sure that the problem is with referencing the subform
controls, but I don't know how to correct it. I think maybe the focus needs
to be set to the subform.

Will appreciate any help/pointers in the right direction. Thanks!

-Amit

PS. Also, just wondering if it is possible to use recursion here to deal
with nested subforms- just a thought, not that I need it...as of now :)

Here's the code with my comments in ">>"
========================================================
Public Function fSpell()
' Arvin Meyer 9/17/1998
' Adapted from code by Terry Wickenden
Dim ctlSpell, sf_ctlSpell As Control

'>>I added sf_ctlSpell to refer to subform controls

Dim frm As Form

Set frm = Screen.ActiveForm
DoCmd.SetWarnings False
' Enumerate Controls collection.
For Each ctlSpell In frm.Controls

'>> I added (ctlSpell.visible = true) as I have some invisible textbox
controls
'>> on my form

If ctlSpell.Visible = True And 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

If TypeOf ctlSpell Is SubForm Then
Forms![frm]![ctlSpell].Forms.SetFocus

'iterate through all the controls of the subform and spellcheck
For Each sf_ctlSpell In frm.ctlSpell.Controls

'>> I've tried a few variations in the above line like
Me!ctlSpell.Forms!Control
'>> and Forms!ctlSpell.Forms!Control w/o success.

If sf_ctlSpell.Visible = True And TypeOf sf_ctlSpell Is
TextBox Then
If Len(sf_ctlSpell) > 0 Then
With sf_ctlSpell
.SetFocus
.SelStart = 0
.SelLength = Len(sf_ctlSpell)
End With
DoCmd.RunCommand acCmdSpelling
End If
End If
Next
End If
Next
DoCmd.SetWarnings True
End Function
========================================================
 
M

Marshall Barton

Amit said:
MS Access 2K, Windows XP
====================
I'm trying to spell check the textbox and memo controls on a form and a
subform. Thanks to Arvin Meyer's code, I'm able to spell-check the controls
on the form.

But, is there a way to spell-check the controls on a subform? I only have
one subform on a form (meaning one level down) and no nested subforms within
a subform.

I modified the code but I'm getting an "Application defined or
object-defined error" when I run the code.

I have a button on the form that calls this function which is defined in a
module. I'm quite sure that the problem is with referencing the subform
controls, but I don't know how to correct it. I think maybe the focus needs
to be set to the subform.

Will appreciate any help/pointers in the right direction. Thanks!

-Amit

PS. Also, just wondering if it is possible to use recursion here to deal
with nested subforms- just a thought, not that I need it...as of now :)

Here's the code with my comments in ">>"
========================================================
Public Function fSpell()
' Arvin Meyer 9/17/1998
' Adapted from code by Terry Wickenden
Dim ctlSpell, sf_ctlSpell As Control

'>>I added sf_ctlSpell to refer to subform controls

Dim frm As Form

Set frm = Screen.ActiveForm
DoCmd.SetWarnings False
' Enumerate Controls collection.
For Each ctlSpell In frm.Controls

'>> I added (ctlSpell.visible = true) as I have some invisible textbox
controls
'>> on my form

If ctlSpell.Visible = True And 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

If TypeOf ctlSpell Is SubForm Then
Forms![frm]![ctlSpell].Forms.SetFocus

'iterate through all the controls of the subform and spellcheck
For Each sf_ctlSpell In frm.ctlSpell.Controls

'>> I've tried a few variations in the above line like
Me!ctlSpell.Forms!Control
'>> and Forms!ctlSpell.Forms!Control w/o success.

If sf_ctlSpell.Visible = True And TypeOf sf_ctlSpell Is
TextBox Then
If Len(sf_ctlSpell) > 0 Then
With sf_ctlSpell
.SetFocus
.SelStart = 0
.SelLength = Len(sf_ctlSpell)
End With
DoCmd.RunCommand acCmdSpelling
End If
End If
Next
End If
Next
DoCmd.SetWarnings True
End Function
========================================================


I think this is what you're looking for:

. . .
If TypeOf ctlSpell Is SubForm Then
ctlSpell.SetFocus

'iterate through all the controls of the subform and
spellcheck
For Each sf_ctlSpell In ctlSpell.Form.Controls
. . .
 
G

Guest

Marshall Barton said:
I think this is what you're looking for:

. . .
If TypeOf ctlSpell Is SubForm Then
ctlSpell.SetFocus

'iterate through all the controls of the subform and
spellcheck
For Each sf_ctlSpell In ctlSpell.Form.Controls
. . .

--

Hi Marshall,

I was out the past few days and just got around to reading your response and
testing it.

I tried the code you recommended, and it gives me the following message on
the subform control: "Object doesn't support this Property or Method".

I have a text control and a memo control on the subform. I get this message
after it spell-checks the first control (text).
The Memo control shouldn't be causing this error, should it?

Please let me know if you have any suggestions on how to correct this.

Thanks.

-Amit
 
G

Guest

Ah, never mind.
I had a Msgbox statement with the name of the control, and that's what
caused the error message. I commented out the statement and it is working
fine.
Thanks Masrhall.
:)

-Amit
 
D

dsc2bjn

I realize the original message is like 3 years old and hope that you still
visit the discussion groups.

I am a VB novice and am having a difficult time understanding exactly where
to fit the subform spell check in with the parent form spell check.

Any help is greatly appreciated.



Marshall Barton said:
Amit said:
MS Access 2K, Windows XP
====================
I'm trying to spell check the textbox and memo controls on a form and a
subform. Thanks to Arvin Meyer's code, I'm able to spell-check the controls
on the form.

But, is there a way to spell-check the controls on a subform? I only have
one subform on a form (meaning one level down) and no nested subforms within
a subform.

I modified the code but I'm getting an "Application defined or
object-defined error" when I run the code.

I have a button on the form that calls this function which is defined in a
module. I'm quite sure that the problem is with referencing the subform
controls, but I don't know how to correct it. I think maybe the focus needs
to be set to the subform.

Will appreciate any help/pointers in the right direction. Thanks!

-Amit

PS. Also, just wondering if it is possible to use recursion here to deal
with nested subforms- just a thought, not that I need it...as of now :)

Here's the code with my comments in ">>"
========================================================
Public Function fSpell()
' Arvin Meyer 9/17/1998
' Adapted from code by Terry Wickenden
Dim ctlSpell, sf_ctlSpell As Control

'>>I added sf_ctlSpell to refer to subform controls

Dim frm As Form

Set frm = Screen.ActiveForm
DoCmd.SetWarnings False
' Enumerate Controls collection.
For Each ctlSpell In frm.Controls

'>> I added (ctlSpell.visible = true) as I have some invisible textbox
controls
'>> on my form

If ctlSpell.Visible = True And 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

If TypeOf ctlSpell Is SubForm Then
Forms![frm]![ctlSpell].Forms.SetFocus
' the above statement needs to be fixed as I got an error message that said
that Access can't find the form "frm"

'iterate through all the controls of the subform and spellcheck
For Each sf_ctlSpell In frm.ctlSpell.Controls

'>> I've tried a few variations in the above line like
Me!ctlSpell.Forms!Control
'>> and Forms!ctlSpell.Forms!Control w/o success.

If sf_ctlSpell.Visible = True And TypeOf sf_ctlSpell Is
TextBox Then
If Len(sf_ctlSpell) > 0 Then
With sf_ctlSpell
.SetFocus
.SelStart = 0
.SelLength = Len(sf_ctlSpell)
End With
DoCmd.RunCommand acCmdSpelling
End If
End If
Next
End If
Next
DoCmd.SetWarnings True
End Function
========================================================


I think this is what you're looking for:

. . .
If TypeOf ctlSpell Is SubForm Then
ctlSpell.SetFocus

'iterate through all the controls of the subform and
spellcheck
For Each sf_ctlSpell In ctlSpell.Form.Controls
. . .
 

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