If,then Statement

alfred67

Registered User.
Local time
Today, 17:54
Joined
Jan 26, 2010
Messages
65
Hello

I can't get my if statement to work in the Query

If <[Start Date] And >[End Date] then [Payment Quantity] = 0

Keep getting error

How should I rewrite it??

Thanks
Alfred67
 
Not sure what you mean by update.

The Payment
 
Well a query doesn't work like you are saying, if you want to do that, then you must use an update query.

Do a google search for update query and do some reading up on them. Post back here if you don't understand then, and I'll try to help you. I am leaving work now, and may not be back on the site until morning. :) Good Luck and welcome to AWF.
 
ooop's sorry not sure what happened

Not sure what you mean by update??

Payment Quantity will have values(amounts) that are within the dates but need to be changed to zero when queried outside the dates.

Hmmm hope I did confuse thing??

Alfred67
 
Ok read about update Query. I would say no its not an update Query.
I don't want to change the value in the table I only what it changed for this Query.

Alfred67
 
That kind of If statement is VBA and not valid in a query.

I also suspect you have your comparators backwards. Anything that is less than a start date is not likely to be also greater than an end date.

I expect you are looking for an Immediate If function.
IIF({condition}, {Value if true}, {Value if false})

Include the field name in each part of the condition.

IIf ([somedatefield]>[Start Date] AND [somedatefield]<[End Date], [Payment Quantity], 0 )
 
This is what I'm trying to do:

Start date= Feb 1/10 and End Date = Feb 28/10
Anything before Feb 1/10 (example Jan 20/10) make Payment Quantity=0
and After Feb 28/10 (example March 3/10) make Payment Quantity=0


Thanks

Alfred67
 
You will need to have your dates in a valid date field format or the comparisons will not work.

Then write the IIF I posted into the Field grid cell of a new field.
It will make a field called Expr1 but you can edit this name.

The field will show the value of [Payment Quantity] for dates between the start and end and zero for those ouside of this range.
 

Users who are viewing this thread

Back
Top Bottom