我有两个陈述,它们本身完美地运作。我试图让他们在一个声明中一起工作,但得到一条错误消息。他们是
Private Sub NextDue_BeforeUpdate(Cancel As Integer)
If Me.NextDue > Me.EndDate Then
MsgBox "Check Rent Review Date"
Cancel = True
End If
End Sub
If Me.NextDue < Date Then
MsgBox "Date in Past"
Cancel = True
End If
End Sub
但是得到编译错误:“Else without If”。我试图添加ElseIf,但得到另一个编译错误:“预期:表达式”。他们可以一起完成吗?
答案 0 :(得分:4)
您需要删除代码中间当前拥有的End Sub
:
Private Sub NextDue_BeforeUpdate(Cancel As Integer)
If Me.NextDue > Me.EndDate Then
MsgBox "Check Rent Review Date"
Cancel = True
ElseIf Me.NextDue < Date Then
MsgBox "Date in Past"
Cancel = True
End If
End Sub