一个IF中的两个独立条件(VBA Access 2010)

时间:2016-07-08 20:07:02

标签: vba if-statement ms-access-2010 conditional-statements

我在表单中有两个条件(VBA Access 2010),它们都是分开工作的。 我把这些条件放在" On Load"相同形式的事件和寻求时间。 第一个"如果"作品(与#34; Pr330USD"字段相关)但其他字段(ExpireDate)不起作用。 " Pr330USD"是一个数字领域和 " EXPIREDATE"是一个日期字段。

以下是代码:

Private Sub Form_Load()

If Me.Pr330USD.Value = "0" Then

    OpenReportFRR.Enabled = False
    OpenFRRDraft.Enabled = True

ElseIf Me.ExpireDate.Value = "" Then

    ValidDateSchedule.Enabled = False
    VDScheduleTable.Enabled = False

Else

    OpenReportFRR.Enabled = True
    OpenFRRDraft.Enabled = False
    ValidDateSchedule.Enabled = True
    VDScheduleTable.Enabled = True

End If

End Sub

....................

Private Sub Pr330USD_BeforeUpdate(Cancel As Integer)

If [Pr330USD].Value = "0" Then

    OpenReportFRR.Enabled = False
    OpenFRRDraft.Enabled = True

Else

    OpenReportFRR.Enabled = True
    OpenFRRDraft.Enabled = False

End If

End Sub

....................

Private Sub ExpireDate_BeforeUpdate(Cancel As Integer)

If Me.ExpireDate.Text = "" Then

    ValidDateSchedule.Enabled = False
    VDScheduleTable.Enabled = False

Else

    ValidDateSchedule.Enabled = True
    VDScheduleTable.Enabled = True

End If

End Sub

....................

我想知道发生了什么,解决方案是什么?

在你告诉我之前,先谢谢你......

Kasra

2 个答案:

答案 0 :(得分:1)

听起来应该是这样的:

Private Sub Form_Load()

    If Me.Pr330USD.Value = "0" Then
        OpenReportFRR.Enabled = False
        OpenFRRDraft.Enabled = True
    Else
        OpenReportFRR.Enabled = True
        OpenFRRDraft.Enabled = False
    End If
    If IsNull(Me.ExpireDate.Value) Then
        ValidDateSchedule.Enabled = False
        VDScheduleTable.Enabled = False
    Else
        ValidDateSchedule.Enabled = True
        VDScheduleTable.Enabled = True
    End If

End Sub

答案 1 :(得分:0)

我改变了行和条件结构的顺序 似乎这段代码有效:

Private Sub Form_Load()

If Me.Pr330USD.Value <> "0" And Me.ExpireDate <> "" Then

    OpenReportFRR.Enabled = True
    OpenFRRDraft.Enabled = False
    ValidDateSchedule.Enabled = True
    VDScheduleTable.Enabled = True

ElseIf Me.Pr330USD.Value <> "0" And Me.ExpireDate = "" Then

    OpenReportFRR.Enabled = True
    OpenFRRDraft.Enabled = False
    ValidDateSchedule.Enabled = False
    VDScheduleTable.Enabled = False

ElseIf Me.Pr330USD.Value = "0" And Me.ExpireDate <> "" Then

    OpenReportFRR.Enabled = False
    OpenFRRDraft.Enabled = True
    ValidDateSchedule.Enabled = True
    VDScheduleTable.Enabled = True

Else

    OpenReportFRR.Enabled = False
    OpenFRRDraft.Enabled = True
    ValidDateSchedule.Enabled = False
    VDScheduleTable.Enabled = False

End If

End Sub