Quick code question

  • Thread starter Thread starter Keypad
  • Start date Start date
K

Keypad

Hello,

I need to check if a value is > 0 and <= 7. I can code it to check a single
condition, but can't write correct code to check two conditions at once. I'm
using the code below to show a criterior based on the value of DaysLeft as
shown below. Can someone write the code to check if DaysLeft is > 0 and <=
7. Many thanks.

Select Case Me.cboReport.Column(1)
Case "Expired"
DoCmd.OpenReport "Expirations", acViewPreview, , "[DaysLeft] <= " & 0

Case "Expires within 7 days"
DoCmd.OpenReport "Expirations", acViewPreview, , "[DaysLeft] <= " & 7

Case "Expires within 30 days"
DoCmd.OpenReport "Expirations", acViewPreview, , "[DaysLeft] <= " & 30

Case "View All Records"
DoCmd.OpenReport "Expirations", acViewPreview
End Select

End Sub
 
Can someone write the code to check if DaysLeft is > 0 and <=
7. Many thanks.

"[DaysLeft] > 0 AND [DaysLeft] <= 7"

It's not necessary to have the values being searched outside the quotes; that
is needed if you're searching for a VBA variable but not needed for a
constant.

What you were probably missing is that the fieldname needs to be there twice.
AND and OR combine *true/false expressions* so you need to compare two
expressions:

[DaysLeft] > 0

and

[DaysLeft] <= 7
 
John,

Thanks a million. The change you made works great, plus I learned something
new in the process. Major thanks my friend :-)

KP

John W. Vinson said:
Can someone write the code to check if DaysLeft is > 0 and <=
7. Many thanks.

"[DaysLeft] > 0 AND [DaysLeft] <= 7"

It's not necessary to have the values being searched outside the quotes; that
is needed if you're searching for a VBA variable but not needed for a
constant.

What you were probably missing is that the fieldname needs to be there twice.
AND and OR combine *true/false expressions* so you need to compare two
expressions:

[DaysLeft] > 0

and

[DaysLeft] <= 7
 
Back
Top