代码不遵循If-Then-Else语句中的预期路径 [英] Code not following expected path in If-Then-Else statement

查看:128
本文介绍了代码不遵循If-Then-Else语句中的预期路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Next按钮,可以移动到我表单上的下一条记录。当表单在最后一条记录上时,我希望下一步按钮变为不可见。判断当前记录是否是最后记录的最简单方法是将Me.CurrentRecord与Me.Recordset.RecordCount进行比较。这是我的代码:

I have created a Next button to move to the next record on my form. I want the Next button to become invisible when the form is on the last record. The simplest way to figure out if the current record was the last one was to compare Me.CurrentRecord to Me.Recordset.RecordCount. Here is my code:

展开 | 选择 | Wrap | 行号

推荐答案

尝试:
展开 | 选择 | Wrap | 行号


这样做了。我假设主要区别在于将Me.Recordset.RecordCount分配给变量并在比较中使用变量。为什么这样做但是使用实际的表达式呢?
That did it. I assume that the main difference is assigning Me.Recordset.RecordCount to a variable and using the variable in the comparison. Why does that work but using the actual expression doesn''t?


现在我肯定有一些原因我不应该这样做;但是,当我需要重新创建自己的记录导航按钮时,我已经在表单上使用了以下代码。我从来没有看到克隆和使用花哨书签等的原因...但是,我再次,我通常只使用DAO记录集,我还没有在连接到SQLServer的FE上出现此故障。

我使用enabled属性;但是,你总是可以使用可见的。

这是这段代码的最简单版本。


你会注意到:移动下一个按钮不会转到新记录,它在最后保存的记录中停止 - 这是设计的。

我还删除了与movefirst,movelast和newrecord控件相关的代码,因为它与问题无关。


您应该可以修改它以用于on_current事件;但是,我不明白为什么你需要做这样的动作。

Now I''m sure there''s a some reason I shouldn''t be doing it this way; however, I''ve been using the following code for ages on forms when I''ve needed to re-create my own record navigation buttons. I''ve never seen the reason to clone and use fancy bookmarking etc... but then again, I''ve normally used just the DAO record sets and I''ve yet to have this fail on the FE connected to the SQLServer.
I use the enabled property; however, you can always use the visible.
This is the simplest version of this code.

You will note: The move next button will NOT goto the new record, it stops on the last saved record - this is by design.
I have also removed the code that related to the movefirst, movelast, and newrecord controls as it does not relate to the question.

You should be able to modify this for use in your on_current event; however, I don''t see why you would need to do such an action.

展开 | 选择 | Wrap | 行号


这篇关于代码不遵循If-Then-Else语句中的预期路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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