引用问题 [英] Referencing problem
问题描述
我在子窗体上的控件的OnExit事件中有代码。代码
在这种情况下正常工作。但是,如果我在
中将相同的代码放在主窗体的Tab控件上的控件的OnExit事件中,则代码
在第2行出错。错误编号为13,描述
为类型不匹配。两个控件都是备注字段。我怀疑
" Screen.ActiveControl.Parent"没有按照预期引用表格。
感谢您的帮助,
马克
''****** ***************
Dim frm As Form
设置frm = Screen.ActiveControl.Parent
如果frm.Dirty = True则
frm.Dirty = False
结束如果
''(其余代码)
''*********************
控件的父级不一定是表单。
它可能是制表符控件(你的例子),或者是另一个控件(例如对于
$ b) $ b附加标签),或选项组(用于组中的按钮),或另一个
表单(用于子窗体控件),依此类推。
也许您可以使用Form.ActiveControl,或者如果您正在调用通用程序,则将引用传递给
控件。
-
Allen Browne - 微软MVP。西澳大利亚州珀斯。
访问用户提示 - http:// allenbrowne.com/tips.html
回复群组,而不是mvps dot org的allenbrowne。
< cm * @ mountain。 netwrote in message
news:11 ********************** @ s13g2000cwa.googlegr oups.com ...
>我在子窗体上的控件的OnExit事件中有代码。代码
在这种情况下正常工作。但是,如果我在
中将相同的代码放在主窗体的Tab控件上的控件的OnExit事件中,则代码
在第2行出错。错误编号为13,描述
为类型不匹配。两个控件都是备注字段。我怀疑
" Screen.ActiveControl.Parent"没有按照预期的方式引用表格。
感谢您的帮助,
Mark
''** *******************
Dim frm As Form
设置frm = Screen.ActiveControl.Parent
如果frm.Dirty = True那么
frm.Dirty = False
结束如果
''(其余代码)
''*********************
感谢Allen,但我迷路了。
我查看了Access97 Developer's Handbook的副本,第3版。并且
发现了一些反对使用Screen.ActiveControl和
Screen.ActiveForm的警告。建议改为使用Me属性。但是
我不适用于全局功能 - 对吗?
在这种情况下,我不认为使用
屏幕有问题.ActiveControl,但是试图通过使用Screen.ActiveControl.Parent或
Screen.ActiveForm来引用
ActiveControl的表单。
>
父母这种情况似乎是ActiveControl所在的TabControl或页面的
TabControl - 而不是子表单
本身。
我不知道如何使用你的建议(Form.ActiveControl) - 我
尝试使用:
如果Form.ActiveControl .Dirty = True然后
Form.ActiveControl.Dirty = False
结束如果
....但我得到了对象不支持此属性或方法
错误。
谢谢,
马克
Allen Browne写道:
控件的父级不一定是表格。
它可能是制表符控件(您的示例),或其他控件(例如,
附加标签),或选项组(对于组中的按钮),或另一个
表单(对于子窗体控件),等等。
也许你可以使用Form.ActiveControl,或传递一个引用e
如果你正在调用一般程序,你可以控制。
-
Allen Browne - 微软MVP。西澳大利亚州珀斯。
访问用户提示 - http:// allenbrowne.com/tips.html
回复群组,而不是mvps dot org的allenbrowne。
< cm * @ mountain。 netwrote in message
news:11 ********************** @ s13g2000cwa.googlegr oups.com ...
我在子窗体上的控件的OnExit事件中有代码。代码
在这种情况下正常工作。但是,如果我在
中将相同的代码放在主窗体的Tab控件上的控件的OnExit事件中,则代码
在第2行出错。错误编号为13,描述
为类型不匹配。两个控件都是备注字段。我怀疑
" Screen.ActiveControl.Parent"没有按照预期引用表格。
感谢您的帮助,
马克
''****** ***************
Dim frm As Form
设置frm = Screen.ActiveControl.Parent
如果frm.Dirty = True则
frm.Dirty = False
结束如果
''(其余代码)
''*********************
<cm*@mountain.net写在留言中
新闻:11 ********************** @ m79g2000cwm .googlegr oups.com ...
" Me"不适用于全局函数 - 对吗?
PMFJI ...如果将表单对象传递给函数,它就可用。
调用libSomeFunction(Me)
libSomeFunction(frm As Form)
问候,
Keith。
www.keithwilby.com
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)
''*********************
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.
<cm*@mountain.netwrote in message
news:11**********************@s13g2000cwa.googlegr oups.com...>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)
''*********************
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.
<cm*@mountain.netwrote in message
news:11**********************@s13g2000cwa.googlegr oups.com...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)
''*********************
<cm*@mountain.netwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
"Me" isn''t applicable in a global function -- right?
PMFJI ... it is available if you pass the form object to the function.
Call libSomeFunction(Me)
libSomeFunction(frm As Form)
Regards,
Keith.
www.keithwilby.com
这篇关于引用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!