Re: An Issue with Tab Controls
- From: banem2@xxxxxxxxx
- Date: Tue, 24 Jun 2008 22:56:14 -0700 (PDT)
On Jun 24, 5:18 pm, JimW <jim.wess...@xxxxxxx> wrote:
On Jun 24, 1:17 am, ban...@xxxxxxxxx wrote:
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
Branislav,
Thank you for the response.
I do have "Set frm = Screen.ActiveForm" in my original code. So, I
replaced my code with your suggestion. I still get the same
performance. Your code works fine on the two text boxes on the main
form, although to make it work there I have to call the function from
the OnExit event rather than the AfterUpdate event. However, it does
not work on the text boxes on the tab pages. It reacts the same as my
code. I've tried calling the function from the both the AfterUpdate
and OnExit events. Each version has their own problems, but neither
works.
I may be destined to use the command button version which works
perfectly, but relies on the user to be diligent enough to click on
it.
Thanks again for your help.
Jim W
Hello Jim,
I just tried modified function with tab control, works fine. I am
sending you on your e-mail database I have created for this purpose.
Regards,
Branislav Mihaljev
Microsoft Access MVP
.
- References:
- An Issue with Tab Controls
- From: JimW
- Re: An Issue with Tab Controls
- From: banem2
- Re: An Issue with Tab Controls
- From: JimW
- An Issue with Tab Controls
- Prev by Date: Re: Query Criteria to Identify Expired Credit Cards
- Next by Date: Re: Query Criteria to Identify Expired Credit Cards
- Previous by thread: Re: An Issue with Tab Controls
- Next by thread: Access 2007 Tabbed Forms Question
- Index(es):
Loading