Hi all, using Access 2010. When I run a query with the following:
[CODE]Type: IIf([qryA].I get "0" instead of "Raw". Can anyone tell me what I am doing wrong please. ThanksCode:="50", [qryB].[Type]=Raw, [qryB].[Type])
Hi all, using Access 2010. When I run a query with the following:
[CODE]Type: IIf([qryA].I get "0" instead of "Raw". Can anyone tell me what I am doing wrong please. ThanksCode:="50", [qryB].[Type]=Raw, [qryB].[Type])
Is the field you are checking a numeric or text field?
If it is a numeric field, you do NOT want double-quotes surrounding the number 50.
Do want an IF?
It looks like it is there, but somehow got messed up in his code tags (note the text just above the code box).Do want an IF?
I wonder if his field name was "Code", and that is confusing things.
the fields are text. Sorry, My code is an IIF statement. Tags didn't grab all
Can you post your formula again without the CODE tags?
This part looks bad too:
If you just want to return the word "Raw", you would have just haveCode:[qryB].[Type]=Raw
in the second argument.Code:...,"Raw",...
I had a field named Code which threw the code tags off. Here you go:
Code:IIf([qryA].[ID]="50", [qryB].[Type]=Raw, [qryB].[Type])AS type
What exactly are you trying to do?
Are you just trying to return a value, or replace the value in your "Type" field.
Note that in Select Queries, calculated fields will only return calculated values. They will not "reset" the value on another field. You would need to use an Update Query to do that.
Maybe this is the calculaton you are looking for (if just wanting to return a value)?
Code:IIf([qryA].[ID]="50","Raw",[qryB].[Type]) as cType
NOTE: "Type" is a reserved word in Access and shouldn't be as object names. It confuses Access and isn't very descriptive.
http://www.allenbrowne.com/AppIssueBadWord.html
Poor choice of field names. See this:
txtCID is a text field with different CIDs such a 10, 20 , 30, 40, 50 etc. CType the type of txtCID also text. I want if txtCID = "50", fill in the CTYpe as "Raw", else use whatever comes up as the CType.Code:IIf([qryA].[txtCID]="50", [qryB].[CType]=Raw, [qryB].[CType]) AS LType
Thanks
See my reply back in post #8.I want if txtCID = "50", fill in the CTYpe as "Raw", else use whatever comes up as the CType.
The problem is this part right here:
There are many issues with this:Code:[qryB].[CType]=Raw
1. Any literal text you want to return needs to be enclosed in double quotes ("Raw")
2. If you just want to return this value for the sake of this calculation, for this second argument you would not use:
but rather just:Code:[qryB].[CType]="Raw"
3. If you want to permanently change the underlying value of your [CType] field, you cannot do it in an IIF statement like that in a calculated field, you need to use an Update Query instead.Code:"Raw"
Re-read posts #2 and #6 by Joe.
Then re-read post #8. (third sentence)
Missing quotes around RAW......should be[qryB].[CType]=Raw
If the "txtCID" field (column) in "qrya" equals a string that is 50 (different than a number 50),Code:[qryB].[CType]= "Raw"
return the result of "[qryB].[CType]="Raw" "
else
return the value from the field (column) "[qryB].[CType]".
in the the field (column) named "LType".
If the string RAW was enclosed in quotes, the returned value for the TRUE part of the IIF() statement would be TRUE if the value in CType = "RAW" and FALSE for all other values of CType.
This is the corrected IIF() statement.... IF "txtCID" is a number and not text.
Code:IIf([qryA].[txtCID]=50, "Raw", [qryB].[CType]) AS LType
Sorry; Raw is surrounded by quotes. Failed to copy and paste my code rather I typed it out such short code. txtCID is a text field as well as the type field. Still returning 0. Please see post #10 outlining fields
Did you address all three issues I commented on in post #11?
If so, please post your current formula, and answer the question about wanting to just return a value or wanting to update the underlying field.
I do not want to change the underlying field. I just want this in the query. He's the correction with "Raw" in quotes and it works:
Thanks so muchCode:IIf([qryA].[txtCID]="50","Raw”, [qryB].[CType]) AS LType