Quick code question

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
 
J

John W. Vinson

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
 
K

Keypad

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
 

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

Similar Threads


Top