Kyle Parisi
Kyle Parisi

Reputation: 1416

Access - VBA if/and/or statements

I'm helping a friend out write some VBA in Access. Here is the line I want to write which I wrote in Excel's VB editor:

If Range("A" & X).Value = "7M" And (Range("B" & X).Value < 300 Or Range("B" & X).Value > 600) Then

I want to group the Or statement in Access but apparently ()s are not good syntax. Should I just nest If statements?

Upvotes: 1

Views: 32765

Answers (1)

HK1
HK1

Reputation: 12210

I'm unable to site the source right now but I did read somewhere recently that this is preferred because it is easier to read and therefore less prone to logical errors:

If Range("A" & X).Value = "7M" Then 
    If Range("B" & X).Value < 300 Then
        'Do Something
    ElseIf Range("B" & X).Value > 600 Then
        'Do Something
    End If
End If

Upvotes: 1

Related Questions