Re: Referencing problem



Sure appreciate the response, David
I'll take some time to try to fully understand your syntax for
referencing the controls.
As mentioned, this code IS being run from the OnExit event.

Re: > Activecontrol does not return the correct reference for controls
embedded in a tab, so it's not usable.
-- in this case it seems to reference the controls correctly, but as I
acknowledged in another post, Access97 Developers' Handbook also does
not recommend using Screen.ActiveControl and I'm certainly willing to
try other ways of referencing.

Re:> SpellCheck(Forms!ParentForm!Subform.Form)
-- I'll try this, at least in the way the control is referenced, but
I'm quessing that it'll need to be in the format of other spellchecking
routines that I've seen: e.g,

Dim ctlSpell As Control
Set ctlSpell = Screen.ActiveControl
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
ctlSpell.SetFocus

Thanks again David,
Mark


David W. Fenton wrote:
cmd@xxxxxxxxxxxx wrote in
news:1154002206.398563.11220@xxxxxxxxxxxxxxxxxxxxxxxxxxxx:

[]

If Me.Parent is subform control

-- I don't think it is (see below)

Well, I wasn't describing your situation. I was outlining what
generic code should be doing.

What you need to return is the form reference that can be used to
set focus to the appropriate form so that the Runcommand will be
applied to the right control.

and it is named "MySubForm", you'd

refer to it as:

Me.Parent.Parent("MySubForm").Form

If the parent is a tab, you'd use:

Me.Parent.Parent

to return a reference to the form the tab is embeded in.

If the tab is on a subform, you'd use:

Me.Parent.Parent.Parent("MySubForm").Form

Make sense?

-- Sorry, no; I think my brain just short-circuited. With a
mainform/subform/tabcontrol/textbox layout, I seem to get the
correct results if I enter the following in the OnExit event for
the textbox:

Dim frm As Form
Set frm = Me.Form
If frm.Dirty Then
frm.Dirty = False
End If

Me.Dirty works because it's running in the original context, i.e.,
in the code behind the subform.

You can't use the Me operator or the form reference returned by Me
in that context because you're running code outside the form's code
module (the Me actually refers to the code module first, and only
secondarily the object it is attached to), and using it to set focus
to a form that is embedded in a tab in a form control inside another
form. The subform doesn't exist as itself, only as a child object
within the parent form.

So, you need a form reference that fully specifies the context in
which the subform is loaded.

-- the above saves the record on the subform (the tabcontrol is
located on this subform and the textbox is located on the
tabcontrol).

-- the following occurs when executed from the OnExit event of the
textbox:

(Debug.Print)

Me.Name = MySubformName
-- I was expecting the name of the textbox from which the event
is
being fired, but I guess the textbox is actually two levels down
from "Me" -- Me/TabControl/Textbox

Me.Form.Name = MySubformName

Me.Parent.Name = MyMainformName

Me.Parent.Form.Name = MyMainformName

Screen.ActiveControl.Name = MyTextBoxName

Screen.ActiveControl.Parent.Name = Page 1

Screen.ActiveControl.Parent.Parent.Name = TabCtl163

Don't use the Screen object. Pass a control reference to the code
that you call from the events of the control you want to spellcheck.

Better yet, pass the form reference. That way you don't have to make
your spellcheck code smart -- you put all the smarts in the context
in which it is called. It would look something like this if your
control is on a tab control on a subform:

SpellCheck(Me.Parent.Parent.Parent(Me.Parent.Parent.Name).Form)

Me.Parent.Parent.Name will return th ename of the subform control
that the subform is embedded in.

Me.Parent.Parent.Parent will return a form reference to the parent
form.

Or, you could do it as:

Dim frm As Form

Set frm = Me.Parent.Parent.Parent

SpellCheck(frm(Me.Parent.Parent.Name).Form)

Of course, if the subform is used in only one parent form, you don't
need to do all of this. Just specify the forms by name:

SpellCheck(Forms!ParentForm!Subform.Form)

You only need to use all the Parent.Parent garbage if you need the
code to run in multiple contexts. A subform that is only ever used
in one parent form can have a hardwired form reference.

If I add "Screen.ActiveControl.Parent.SetFocus" to the end of the
code (after acCmdspell), then on exit from the textbox and
Spellcheck the cursor moves to an unbound textbox I placed on the
tabcontrol (first in tab ordering) and the focus is not stuck on
the textbox from which the code is run. Without this, however,
there is evidently some loop going on that keeps the focus on the
textbox.

Activecontrol does not return the correct reference for controls
embedded in a tab, so it's not usable.

Indeed, I would hardly ever recommend using it.

So, if the record is correctly being saved first as specified in
the code, and Screen.ActiveControl is correctly specifiying the
textbox in question, and Spellcheck is correctly checking that
textbox, then what's causing the loop or keeping the focus on that
textbox -- why can't you tab out of, or otherwise escape from that
textbox?

Well, that I don't know. I wouldn't expect the code to run properly
at all.

What event are you running it in?

I would recommend the OnExit event, as you can't use AfterUpdate or
BeforeUpdate.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/

.



Relevant Pages

  • Re: refresh an open form using records from another open form?
    ... Yes, I made the linking textbox visible, and yes the record ID's match ... It's as if the subform only wakes up when I click on it?... ... I click a control on the 'frm_Road_Junctions' form. ... Did you set up the master/child link for the subform control containing ...
    (microsoft.public.access.formscoding)
  • Re: Does a textbox have to have a name reference, or can I use a w
    ... for referencing an outside form (that is, not the current form or subform): ... subform control, which is to say the actual form being used as a subform. ... PreviousControl can reference only one control. ... Debug.Print stAppName ...
    (microsoft.public.access.formscoding)
  • Re: Error 2455 (associated with subform reference)
    ... Products combo box in the subform, and to set the criteria for VendorID to ... the main form control. ... The good news is that I don't need to reference subform controls in the ... could probably pass over the error message in the code's error handling, ...
    (microsoft.public.access.formscoding)
  • Re: list box from query
    ... When you reference ... with the name of the parent form ... SubFormControlName: with the name of the subform control on the parent form. ...
    (microsoft.public.access.formscoding)
  • Re: Refresh certain txtboxes on a page with Form referenes
    ... Nice approaches (and yes, it's a "tab control") ... does the subform on page 1 need to be a subform? ... A text box in a sub form on the first page has a reference like this, ...
    (microsoft.public.access.formscoding)