VBA-using different data types in an iif statement

HappyLadyToo

Board Regular
Joined
Aug 28, 2012
Messages
64
Good Morning,

I've built a query in Access and am have a data type mismatch in an IIF statement. I know where the problem is but I don't know how to fix. Last night, two of us worked on for 4 hours. Ugh!

When I use each part of the IIF statement separately, they work. I cannot put them together or the column errors out. What I want to do is this:

The query needs to find and count higher than 0 in the CBKO Qty column first. If the count is more than zero, the priority column will read 1 for that product. Should that be false, the next step is to compare the PO Due Date to today. If the PO Due Date is prior to today, the priority column will read 2 for that product. If neither of theses conditions are true, the column will be blank.

The error is either #ERROR or is a date to a Julian number. Please help!


Code:
SELECT 
[Part Detail].[Report Date], 
[zzz Short PO to Product PO].DC_CODE, 
[zzz Short PO to Product PO].PART_NUMBER, 
[Part Detail].[CBKO Qty], 
[Part Detail].[FBKO Qty],
 [zzz Short PO to Product PO].PO, 
[zzz Short PO to Product PO].[PO Date], 
[zzz Short PO to Product PO].PO_Due_Date,
 [zzz Short PO to Product PO].ITEM_CODE, 
[zzz Short PO to Product PO].QTY_ORDERED, 
[zzz Short PO to Product PO].QTY_RECEIVED,
 [B]IIf([CBKO Qty]>0,1,IIf([PO_Due_Date]<Now(),2,"")) AS Priority,[/B] 
[zzz Short PO to Product PO].VENDOR_NAME


FROM 
[zzz Short PO to Product PO] LEFT JOIN [Part Detail] ON ([zzz Short PO to Product PO].LINE_CODE = [Part Detail].[Line Code]) AND ([zzz Short PO to Product PO].ITEM_CODE = [Part Detail].[Item Code]) AND ([zzz Short PO to Product PO].DC_CODE = [Part Detail].[DC Name]);
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Not sure how to delete it or post as solved.​
The best thing to do is to post the solution (so that others can see what the problem was and how it was corrected). You may be able to help/educate others!
 
Upvote 0
The problem is that I was missing single quotes around the numbers in my IIF statement. Something so simple was causing a lot of grief.

It looks like my IIF statement was missing some data in my post.




Good Morning,

I've built a query in Access and am have a data type mismatch in an IIF statement. I know where the problem is but I don't know how to fix. Last night, two of us worked on for 4 hours. Ugh!

When I use each part of the IIF statement separately, they work. I cannot put them together or the column errors out. What I want to do is this:

The query needs to find and count higher than 0 in the CBKO Qty column first. If the count is more than zero, the priority column will read 1 for that product. Should that be false, the next step is to compare the PO Due Date to today. If the PO Due Date is prior to today, the priority column will read 2 for that product. If neither of theses conditions are true, the column will be blank.

The error is either #ERROR or is a date to a Julian number. Please help!


Code:
SELECT 
[Part Detail].[Report Date], 
[zzz Short PO to Product PO].DC_CODE, 
[zzz Short PO to Product PO].PART_NUMBER, 
[Part Detail].[CBKO Qty], 
[Part Detail].[FBKO Qty],
 [zzz Short PO to Product PO].PO, 
[zzz Short PO to Product PO].[PO Date], 
[zzz Short PO to Product PO].PO_Due_Date,
 [zzz Short PO to Product PO].ITEM_CODE, 
[zzz Short PO to Product PO].QTY_ORDERED, 
[zzz Short PO to Product PO].QTY_RECEIVED,
 [B]IIf([CBKO Qty]>0,[U]'1',[/U]IIf([PO_Due_Date]<now(),2,"")) as="" priority,<="" strong=""> < NOW(), [U]'2',[/U]"")),
[zzz Short PO to Product PO].VENDOR_NAME


FROM 
[zzz Short PO to Product PO] LEFT JOIN [Part Detail] ON ([zzz Short PO to Product PO].LINE_CODE = [Part Detail].[Line Code]) AND ([zzz Short PO to Product PO].ITEM_CODE = [Part Detail].[Item Code]) AND ([zzz Short PO to Product PO].DC_CODE = [Part Detail].[DC Name]);

</now(),2,""))>[/B]
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top