Use If to check for multiple TRUE conditions?

R

RoadKyng

Tried to use IF and IF. It fails. Haven't found a solution. Suggestions?

'check for data in mandatory data fields
If Me.IntervalType = "Hours" Or Me.IntervalType = "Cycles" And
IsNull(Me.Interval) Or Me.Interval = "" Then
MsgBox "ENTER THE TASK ITEM/S INTERVAL"
DoCmd.GoToControl "Interval"
 
D

Douglas J. Steele

Try putting in parentheses.

Assuming that you want the message box to appear if the IntervalType is
either Hours or Cycles and the Interval is either Null or blank, try:

If (Me.IntervalType = "Hours" Or Me.IntervalType = "Cycles") And
(IsNull(Me.Interval) Or Me.Interval = "") Then

And takes precedence over Or

You can simplify the check for Null or blank as:

Len(Me.Interval & vbNullString) = 0
 
F

fredg

Tried to use IF and IF. It fails. Haven't found a solution. Suggestions?

'check for data in mandatory data fields
If Me.IntervalType = "Hours" Or Me.IntervalType = "Cycles" And
IsNull(Me.Interval) Or Me.Interval = "" Then
MsgBox "ENTER THE TASK ITEM/S INTERVAL"
DoCmd.GoToControl "Interval"

Well I'm confused as to how to group the various criteria.

Try putting parenthesis around the criteria.

For example:
Is it:
If (Me.IntervalType = "Hours" Or Me.IntervalType = "Cycles") And
(IsNull(Me.Interval) Or Me.Interval = "") Then ...

where intervalType = "Hours" or "Cycles"
AND Interval is Null or ""

or
If Me.IntervalType = "Hours" Or (Me.IntervalType = "Cycles" And
IsNull(Me.Interval) Or Me.Interval = "") Then ...

where IntervalType = "Hours"
OR intervalType = "Cycle" And Interval is null or ""

or
If (Me.IntervalType = "Hours" Or Me.IntervalType = "Cycles" And
IsNull(Me.Interval)) Or Me.Interval = "") Then ...

where IntervalType = "Hours" or "Cycle" and Interval is null
OR Interval is ""


If that doen't help, then simplify the statement by starting with one
condition and adding a condition until it fails.
 
R

RoadKyng

Sorry for the confusion.

There are two different classes of inspection intervals - Hourly/Cyclical -
of which the value is an integer, or a Calendar value. What I am testing for
is the interval class. Then I want to make sure the user has entered an
integer for how long of an extension is wanted ie 10 hours, or 10 cycles, or
10 days, or 10 months etc.

The reason for this is calculations downstream that take the original due
point (be it hours/cycles or a calendar value) and adds the extension to it.
The first test is to find out what inspection interval we have and the second
test is to make sure we have a number in the extension field to perform a
calculation with.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top