Re: Referencing problem



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: label control wont update
    ... I did remove the label and put in a textbox instead and then ... I do need change event code because the 2nd tab is a drill down from the ... On the first tab you set focus to a row on the subform. ...
    (microsoft.public.access.formscoding)
  • Re: label control wont update
    ... in the tab control's Change event. ... Your post didn't contain what you used to get the subform ... >put txtamounttotal value right into the textbox from there using ... >I do need change event code because the 2nd tab is a drill down from the ...
    (microsoft.public.access.formscoding)
  • Re: Referencing problem
    ... I just saw your other post about spell checking. ... nor do I know if it's possible do to this with a subform. ... moves out of a textbox or memo field. ... to return a reference to the form the tab is embeded in. ...
    (comp.databases.ms-access)
  • 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: Tab functionality for VBA form in Excel 2004 for mac / macinto
    ... I do have the Mac set to tab from textbox to textbox and ... computer with Excel 2008. ... One of the problems I can't fix, however, is the tab functionality of the ... I must click in each box to move the control. ...
    (microsoft.public.mac.office.excel)

Loading