最好的(正确的)方式 [英] The best (correct?) way

查看:54
本文介绍了最好的(正确的)方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

什么是最好的(正确?)方式:


Me.txtCustID.SetFocus

在OnLoad或OnOpen或表格中的

Hi!
What is the best (correct?) way to do:

Me.txtCustID.SetFocus

in the OnLoad or in the OnOpen or... of the form?

推荐答案

Geir Baardsen写道:
Geir Baardsen wrote:
嗨!
最好的(正确的)方法是什么:

Me.txtCustID.SetFocus

在OnLoad或者表单的OnOpen或...?
Hi!
What is the best (correct?) way to do:

Me.txtCustID.SetFocus

in the OnLoad or in the OnOpen or... of the form?




在设计视图中将它的TabIndex属性设置为0,忘记代码。打开表单时,IT $

会有焦点。

但是如果txtCustID在表单页眉或页脚中,则使用一些代码
$在OnOpen中b $ b。


BTW你的语法很少,点是属性和方法,

使用爆炸你的对象,例如


Me!txtCustID

Me(" txtCustID")这是

Me.Controls(" txtCustID")的缩写


曾经有一个小规则,如果MS创建它,那就是我。否则,如果你创建它是
就是我!


如果对象具有相同的名称,使用Me.ControlName会导致问题

作为一种可能造成混淆的财产或方法,要么产生意外结果,要么稍后让开发人员混淆看看

代码的人。另外,它可以产生随机的编译错误,一分钟就可以了。

编译好了下一次它没有。



Set it''s TabIndex property to 0 in design view, forget the code. IT will
have the focus when the form is opened.

If however txtCustID is in the form header or footer then use some code
in OnOpen.

BTW your syntax is little off, the dot is for properties and methods,
use a bang for your objects, e.g.

Me!txtCustID
Me("txtCustID") which is short for
Me.Controls("txtCustID")

There used to be a little rule, if MS created it, it was Me. else if you
created it it was Me!

Using Me.ControlName can cause problems, if an object has the same name
as a property or method it can create confusion, either produce
unexpected results or just confuse a developer later on who looks at the
code. Additionally, it can produce random compile errors, one minute it
compiles OK the next it doesn''t.


Trevor Best< nospam @本地>写道:
Trevor Best <nospam@localhost> wrote:
使用Me.ControlName可能会导致问题,如果一个对象具有相同的名称
作为属性或方法可能会产生混淆,要么产生意外结果或者只是让开发人员稍后混淆谁看了
代码。另外,它可以产生随机的编译错误,一分钟就可以编译好了,接下来它就不行了。
Using Me.ControlName can cause problems, if an object has the same name
as a property or method it can create confusion, either produce
unexpected results or just confuse a developer later on who looks at the
code. Additionally, it can produce random compile errors, one minute it
compiles OK the next it doesn''t.




这很有意思。我总是使用Me.ControlName,但我所有的控制名称

都有前缀,如''txt''(文本框)和''cbo''(组合框) - 是这个

比较安全吗?我似乎没有得到任何编译错误。 A97顺便说一句。



That''s interesting. I always use Me.ControlName but all my control names
have prefixes such as ''txt'' (text box) and ''cbo'' (combo box) - is this
relatively safe? I don''t seem to get any compile errors. A97 BTW.


那是安全的,基思。


我用点,不用打扰绑定控件的前缀(即

控件与字段名称相同)。


我见过的唯一问题是当字段是*不*由表单上的

控件表示,您将该字段称为:

Me.MyField

该案例可以(但并不总是)触发Trevor

所引用的奇怪问题。


似乎没有控制的字段是未记录的类型

AccessField,实现方式必定存在一些错误。一个

可能相关的情况可能导致Access 2002崩溃(可能还有2003)。

这可能发生在子窗体控件的LinkChildFields属性

指的是AccessField类型(即子表单的RecordSource中的字段,

,不是由子表单中的文本框表示)。添加一个文本框

这个外键字段可以阻止崩溃。


顺便说一句,我更喜欢这个点的原因是如果我错误输入控件名,它是在编译时捕获的



-

Allen Browne - 微软MVP。西澳大利亚州珀斯。

访问用户提示 - http:// allenbrowne.com/tips.html

回复群组,而不是mvps dot org的allenbrowne。


" Keith Wilby" <柯********* @ AwayWithYerCrap.com>在消息中写道

news:Xn ************************ @ 10.15.188.42 ...
That''s safe, Keith.

I use the dot, and don''t bother with the prefix for bound controls (i.e. the
control has the same name as the field).

The only problem I''ve seen is when the field is *not* represented by a
control on the form, and you refer to the field as:
Me.MyField
That case can (but does not always) trigger the strange issue that Trevor
refers to.

It seems that the field-without-control is of the undocumented type
AccessField, and there must be some bugs in the way it is implemented. A
possibly related case can cause Access 2002 to crash (and possibly 2003).
That can happen where the LinkChildFields property of a subform control
refers to an AccessField type (i.e. a field in the subform''s RecordSource,
that is not represented by a text box in the subform). Adding a text box for
this foreign key field stops the crashes.

BTW, the reason I prefer the dot is that if I mistype the control name, it
is caught at compile time.

--
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.

"Keith Wilby" <ke*********@AwayWithYerCrap.com> wrote in message
news:Xn************************@10.15.188.42...
Trevor Best< nospam @ localhost>写道:
Trevor Best <nospam@localhost> wrote:
使用Me.ControlName可能会导致问题,如果一个对象具有相同的名称
作为属性或方法可能会产生混淆,要么产生意外结果或者只是让开发人员稍后混淆谁看了
代码。另外,它可以产生随机的编译错误,一分钟它就编译好了,接下来它就不行了。
Using Me.ControlName can cause problems, if an object has the same name
as a property or method it can create confusion, either produce
unexpected results or just confuse a developer later on who looks at the
code. Additionally, it can produce random compile errors, one minute it
compiles OK the next it doesn''t.



这很有意思。我总是使用Me.ControlName,但我的所有控件名称都有前缀,如''txt''(文本框)和''cbo''(组合框) - 这个
相对安全吗?我似乎没有得到任何编译错误。 A97 BTW。



That''s interesting. I always use Me.ControlName but all my control names
have prefixes such as ''txt'' (text box) and ''cbo'' (combo box) - is this
relatively safe? I don''t seem to get any compile errors. A97 BTW.



这篇关于最好的(正确的)方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆