如何根据参数打开一种或另一种表单?

发布于 2024-12-03 11:25:58 字数 486 浏览 0 评论 0原文

有人可以帮助我吗? 这听起来很简单,但我不确定是否可以做到。 这个想法是:如果参数存在则打开该记录,否则打开一个新记录来输入数据。

这是我的尝试,但我什至还无法让它运行。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

時窥 2024-12-10 11:25:58

修改您的空比较。作为一个例子,请从您的 If 条件考虑这一点:

Me.Title <> null

没有任何东西可以“不等于”Null,就像没有任何东西可以“等于”Null。甚至另一个 Null 也不能等于 Null(或不等于 Null)。

因此,无论 Me.Title 为 Null 还是包含非 Null 值,该表达式都将返回 Null。您需要一个返回 True 或 False 的表达式。使用 IsNull() 函数。

If Not IsNull(Me.Title) Then
   'do what you want for a non-Null Title here '
End If

对于“打开特定的 f_Eval”要求,请将WhereCondition 参数与 OpenForm 方法。这是从该链接页面复制的示例。它将打开一个名为“Employees”的表单,并将该表单的记录源限制为“LastName”为“King”的那些行。

DoCmd.OpenForm "Employees", , ,"LastName = 'King'"

因此,OpenFormWhereCondition 就像查询中不带 WHERE 一词的 WHERE 子句。

Revise your Null comparisons. As one example, consider this piece from your If condition:

Me.Title <> null

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.

If Not IsNull(Me.Title) Then
   'do what you want for a non-Null Title here '
End If

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

DoCmd.OpenForm "Employees", , ,"LastName = 'King'"

So the OpenForm WhereCondition is like the WHERE clause in a query without the word WHERE.

薆情海 2024-12-10 11:25:58

你的第一个陈述在我看来是错误的。一方面,我怀疑你的意思是“行动”。尝试一下

If (Me.Type = "Act" _
    And Me.Title <> Null _
    And Me.Section <> Null) _
    Or (Instr("Proposed,Final",Me.Type) >0 
    And Me.Rule <> Null )

,我不相信您从代码中剪切并粘贴了示例,最好这样做。

Your first statement looks wrong to me. I suspect you mean "Act", for one thing. Try

If (Me.Type = "Act" _
    And Me.Title <> Null _
    And Me.Section <> Null) _
    Or (Instr("Proposed,Final",Me.Type) >0 
    And Me.Rule <> Null )

I do not believe you cut and pasted your example from your code, it is best to do so.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文