Re: Referencing problem



Thanks Allen, but I'm lost.

I checked my copy of the Access97 Developer's Handbook, 3rd ed. and
found several cautions against using Screen.ActiveControl and
Screen.ActiveForm. The suggestion was to use Me properties instead. But
"Me" isn't applicable in a global function -- right?

In this case, I don't think there's a problem using
Screen.ActiveControl, but there is trying to reference the
ActiveControl's form by using Screen.ActiveControl.Parent or
Screen.ActiveForm.

"Parent" is this case appears to be the TabControl or Page of the
TabControl on which the ActiveControl exists -- rather than the subform
itself.

I wasn't sure how to use your suggestion (Form.ActiveControl) -- I
tried using:

If Form.ActiveControl.Dirty = True Then
Form.ActiveControl.Dirty = False
End If

.... but I get an "object doesn't support this property or method"
error.

Thanks,
Mark


Allen Browne wrote:
The Parent of a control is not necessarily the form.
It could be the tab control (your example), or another control (e.g. for an
attached label), or an option group (for a button in the group), or another
form (for a subform control), and so on.

Perhaps you could use use Form.ActiveControl, or pass a reference to the
control if you are calling a generic procedure.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<cmd@xxxxxxxxxxxx> wrote in message
news:1153860481.620997.326180@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have code in the OnExit event of a control on a subform. The code
works properly in this instance. If, however, I put the same code in
the OnExit event of a control on a Tab Control of a main form, the code
errors out at the 2nd line. The error number is 13 and the description
is "Type mismatch". Both controls are memo fields. I suspect that
"Screen.ActiveControl.Parent" is not referencing the form as intended.

Thanks for any help,
Mark


'*********************
Dim frm As Form
Set frm = Screen.ActiveControl.Parent
If frm.Dirty = True Then
frm.Dirty = False
End If

'(rest of the code)
'*********************

.