如何根据参数打开一种或另一种表单?
有人可以帮助我吗? 这听起来很简单,但我不确定是否可以做到。 这个想法是:如果参数存在则打开该记录,否则打开一个新记录来输入数据。
这是我的尝试,但我什至还无法让它运行。
Private Sub Form_Load()
If (Me.Type = Act _
and Me.Title <> null _
and section <> null) _
or Me.Type in ('Proposed','Final')
and Me.Rule <> null
Then
Docmd.OpenForm "F_Eval" (but open that specific f_Eval)
Else
Docmd.OpenForm "F_NewEval" (to enter new record)
End If
End Sub
Could someone please help me.
This sounds simple but I'm at the point that I'm not sure if it can be done.
The idea is: If parameters exist than open that record, else open a new one to enter data.
This is my attempt but I can't even get it to run yet.
Private Sub Form_Load()
If (Me.Type = Act _
and Me.Title <> null _
and section <> null) _
or Me.Type in ('Proposed','Final')
and Me.Rule <> null
Then
Docmd.OpenForm "F_Eval" (but open that specific f_Eval)
Else
Docmd.OpenForm "F_NewEval" (to enter new record)
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
修改您的空比较。作为一个例子,请从您的 If 条件考虑这一点:
没有任何东西可以“不等于”Null,就像没有任何东西可以“等于”Null。甚至另一个 Null 也不能等于 Null(或不等于 Null)。
因此,无论 Me.Title 为 Null 还是包含非 Null 值,该表达式都将返回 Null。您需要一个返回 True 或 False 的表达式。使用 IsNull() 函数。
对于“打开特定的 f_Eval”要求,请将WhereCondition 参数与 OpenForm 方法。这是从该链接页面复制的示例。它将打开一个名为“Employees”的表单,并将该表单的记录源限制为“LastName”为“King”的那些行。
因此,OpenFormWhereCondition 就像查询中不带 WHERE 一词的 WHERE 子句。
Revise your Null comparisons. As one example, consider this piece from your If condition:
Nothing can ever be "not equal to" Null, same as nothing can ever be "equal to" Null. Not even another Null can be equal to Null (or not equal to Null).
So whether Me.Title is Null or contains a non-Null value, that expression will return Null. You want an expression which returns either True or False. Use the IsNull() function.
For your "open that specific f_Eval" requirement, use the WhereCondition argument with the OpenForm Method. Here is an example copied from that linked page. It will open a form named Employees and restrict the form's record source to those rows where the LastName is "King".
So the OpenForm WhereCondition is like the WHERE clause in a query without the word WHERE.
你的第一个陈述在我看来是错误的。一方面,我怀疑你的意思是“行动”。尝试一下
,我不相信您从代码中剪切并粘贴了示例,最好这样做。
Your first statement looks wrong to me. I suspect you mean "Act", for one thing. Try
I do not believe you cut and pasted your example from your code, it is best to do so.