Wolfie84367
Wolfie84367

Reputation: 112

If, then, else function in access

I am using the below code in access.

I am trying to set it so that the 2 text boxes can not be left blank, if they have dates in then it will proceed to generate a report.

    If IsNull(Me.txtStart.Value) Then
    MsgBox "Please ensure that both date fields are populated"
    Exit Sub
ElseIf IsNull(Me.txtEnd.Value) Then
    MsgBox "Please ensure that both date fields are populated"
    Exit Sub
Else
End If

Thank you in advance

Upvotes: 0

Views: 569

Answers (1)

Andre
Andre

Reputation: 27634

Just use

If IsNull(Me.txtStart.Value) Or IsNull(Me.txtEnd.Value) Then
    MsgBox "Please ensure that both date fields are populated"
    Exit Sub
End If
' open the report here

No need to use Else after an Exit Sub.

Actually I prefer this coding style for initial checks over large Else cases.

Upvotes: 2

Related Questions