在距离当前日期最近的记录上打开子表单 [英] Open a subform on a record closest to today's date

查看:103
本文介绍了在距离当前日期最近的记录上打开子表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正试图让MS Access自动将光标移动到项目管理数据库中子窗体中今天日期附近的记录(frmvw_milestones )。主窗体(FRM_staff_project)具有项目信息,它包含一个子窗体(frmvw_milestones),其中包含有关某些项目中重要里程碑的详细信息。子表单显示工作人员会计年度的所有里程碑。我想在表单中向下移动光标,以便工作人员在打开表单时看到他/她当前的里程碑,而不必向下滚动。


以下代码几乎可以工作:

Hi,

I''m trying to get MS Access to automatically move the cursor to the record near today''s date within a subform in a project management database (frmvw_milestones). The Main form (FRM_staff_project) has the project information and it includes a subform (frmvw_milestones) that has details about the important milestones within certain projects. The subform shows all the milestones for the fiscal year for the staff member. I want to move the cursor down within the form so that the staff member sees his/her current milestones upon opening the form instead of having to scroll down.

The following code almost works:

展开 | 选择 | Wrap | 行号

推荐答案

Karen,


欢迎使用字节!


首先,作为行政记录,在将代码发布到此论坛时,请使用代码标签在文本编辑器中,用户可以更轻松地查看代码并进行调试。我已经这样做了,并调整了一些格式,所以事情不必向右滑动到右边....


其次,我必须假设字段 tbl_pria_projects.ID_staff 是查询 qryvw_milestones 的一部分。如果没有,那么这绝对是你问题的一部分。我可以假设它不是,因为你用表名和字段名明确声明它。如果它是您的查询的一部分,它可能只是 ID_Staff 。这应该通过添加 ID_Staff 作为查询的输出字段来纠正(您必须将Staff表连接到您的查询)。


第三,另一个问题与SQL语句的语法有关。您必须在SQL语句中使用表单中的 ,而不是仅在 WHERE中列出 code>子句。此外,通常最好先确定您要查找的内容,将其分配给变量,然后在SQL WHERE 子句中使用该变量。这就是我所说的[假设你的代码中所有其他内容保持不变]:

Karen,

Welcome to Bytes!

First, as an administrative note, when posting code to this forum, please use the code tags in your text editor, as it is easier for users to see your code and debug it. I''ve done so above, as well as adjusted some formatting so things don''t have to slide so far to the right....

Second, I must assume that the field tbl_pria_projects.ID_staff is part of the query qryvw_milestones. If not, then this is definitely part of your problem. I may presume that it is not, since you are declaring it explicitly with the table name and the field name. If it was part of your Query, it would probably simply be ID_Staff. This should be corrected by adding the ID_Staff as an output field of your Query (you will have to join the Staff table to your Query).

Third, an additional problem has to do with the syntax of your SQL statement. You must use the value from your form within the SQL statement, and not just list it within the WHERE clause. Additionally, it is often better to determine what it is you are looking for first, assign it to a variable, and then use that variable within your SQL WHERE clause. Here is what I am talking about [assuming all else remains the same in your code]:

展开 | 选择 | Wrap | 行号


谢谢twinnyfo!


是的,字段 tbl_pria_projects.ID_staff 是查询 qryvw_milestones 的一部分。您建议的编码稍作修改:

Thanks twinnyfo!

Yes, field tbl_pria_projects.ID_staff is part of the query qryvw_milestones. Your suggested coding worked with one slight modification:


展开 | 选择 | Wrap | 行号



无论如何,当发生这种情况时,是否有隐藏子表格或显示空白记录?
Is there anyway to hide the subform or show a blank record when this occurs?



实际上这很容易。由于您在转到特定记录之前使用ID_Staff知道此人,因此请检查用户是否在相关记录集中有任何里程碑。然后,一个简单的 If ... Then ... Else 。你有然后部分; Else 将是这样的:

This is actually quite easy. Since you know the person, using ID_Staff, before you go to the particular record, check to see if the user has any Milestones in the recordset in question. Then, a simple If ... Then ... Else. You have the Then part; the Else would be something like this:

展开 | 选择 | 换行 | 行号


这篇关于在距离当前日期最近的记录上打开子表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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