Re: An Issue with Tab Controls



On Jun 23, 11:45 pm, JimW <jim.wess...@xxxxxxx> wrote:
I am using the following function which I found on the Internet to
spell
check certain text boxes on a form. The complete code also included
the
ability to spell check all text boxes that meet certain criteria. I've
tried that version from a command button and it works perfectly.
However, I prefer to spell check automatically upon exiting a specific
text box by calling the function from the OnExit event. This works
fine
on the text boxes on the main form. However, I have text boxes on four
tabs that I also want to check. Upon exiting any one of those text
boxes, the form hangs up in that text box and all the text is
highlighted in black. The only way out is to go to design view,.
Sometimes when going to design view I get Error 2475: You entered an
expression that requires a form to be the active window.  With the
command
button all the designated text boxes are successfully checked whether
on
the main form or any of the Tab Pages.

I call the function as follows:
Private Sub txtDIMName_Exit(Cancel As Integer) fSpell End Sub

Any thoughts on how to eliminate the problem with a text box on a tab
or
am I destined to use the command button version?

Thanks,
JimW

Public Function fSpell()
'**********************************************
'Name: fSpell (Function)
'Purpose: Spell check current field or fields.
'Author: John Spencer UMBC-CHPDM
'Date: October 31, 2002, 01:15:31 PM
'Control on form must be a textbox and have tag property 'that
contains
the phrase "SpellCheck"
'**********************************************

Dim ctlSpell As Control
Dim frm As Form

'---------------------------------------------------------------------
'---------------------------------------------------------------------
' Code to check a textbox control on form when called from form.
'---------------------------------------------------------------------
'---------------------------------------------------------------------

On Error GoTo fSpell_Error

Set frm = Screen.ActiveForm
Set ctlSpell = frm.ActiveControl

DoCmd.SetWarnings False ' turns off the warnings so dialog box doesn't
'
keep popping up for every text box saying ' spell check complete

With ctlSpell
If InStr(1, Nz(.Tag), "SpellCheck", vbTextCompare) <> 0 And _ .Locked
=
False And _ .Enabled = True And _ TypeOf ctlSpell Is TextBox And _
Len(Trim(ctlSpell & vbNullString)) > 0 Then

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

DoCmd.RunCommand acCmdSpelling

End If
End With

DoCmd.SetWarnings True ' warnings turned back on

fSpell_Exit:
Exit Function

fSpell_Error:
If Err.Number = 2474 Then
'No Active control on current form
'Therefore we shouldn't be spellchecking Else MsgBox Err.Number & ": "
&
Err.Description, , "Error in fSpell (Spell Check Routine)"
End If
Resume fSpell_Exit

End Function

Hello,

Make sure that form does not lose focus as this function needs to know
which form has focus in order to run spell check (Set frm =
Screen.ActiveForm); i.e. if you run it in debug mode it will report
the error you got.

If you still has same issue you may try the following modified
function:

Public Function fSpell2(ctl As Control)
DoCmd.SetWarnings False
'turns off the warnings so dialog box doesn't
'keep popping up for every text box saying
'spell check complete

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

DoCmd.SetWarnings True
' warnings turned back on

fSpell_Exit:
Exit Function

fSpell_Error:
If Err.Number = 2474 Then
'No Active control on current form
'Therefore we shouldn't be spellchecking
Else: MsgBox Err.Number & ": " & Err.Description, , _
"Error in fSpell (Spell Check Routine)"
End If
Resume fSpell_Exit

End Function

To call the function place the following in AfterUpdate event:

=fspell2([screen].[activecontrol])

Above function does not require the form to have a focus, so you can
track the code in debug mode too. Hope this helps.

Regards,
Branislav Mihaljev
Microsoft Access MVP
.


Loading