hopelessinsalem
asked on
IIF in Control Source
I have an IIF statement in a control source for X. Statement is as follows: (I have not considered the 'False' part of the statement yet, so ignore that)
=IIf([PrevCurHold]=2,DLook Up([Finali zed],[qryC urYearForm Fill],[Tru ckID]=105 And Month([MonthYr])=7),"False statement here")
Basically trying to lookup the value of "Finalized" in my query Where "TruckID" = 105 and the Month of "MonthYr" = July, but not sure how to write the code for the IIF statement. What I have does not work obviously.
Thanks for any help
=IIf([PrevCurHold]=2,DLook
Basically trying to lookup the value of "Finalized" in my query Where "TruckID" = 105 and the Month of "MonthYr" = July, but not sure how to write the code for the IIF statement. What I have does not work obviously.
Thanks for any help
=IIf([PrevCurHold]=2,DLook Up("[Final ized]","[q ryCurYearF ormFill]", "[TruckID] =") & 105 And Month([MonthYr])=7),"False statement here")
You need to put the field, query and criteria in quotes in your DLookup:
=IIf([PrevCurHold]=2,DLook Up("Finali zed","qryC urYearForm Fill","Tru ckID =105 And Month([MonthYr])=7"),"Fals e statement here")
=IIf([PrevCurHold]=2,DLook
oops
=IIf([PrevCurHold]=2,DLook Up("[Final ized]","[q ryCurYearF ormFill]", "[TruckID] =" & 105 & "And Month([MonthYr])=" & 7),"False statement here")
=IIf([PrevCurHold]=2,DLook
ASKER
Morning Folks,
Ok, I tried both your suggestions and I get an error of "Data Type Mismatch in Criteria"
The field for this control source is a text box.
'Finalized' is a text field
'TruckID' is a a text field
'MonthYr' is a Date field formatted to "mmm yyyy"
I'm not sure, but I'm positive it's that I'm missing the correct way to enter in the string criteria for the date, this being for the month of July.
I even tried this as an attempt, but got the error message "Syntax error in date in query expression"
=IIf([PrevCurHold]=2,DLook Up("[MileE ndLoc]","[ qryCurYear FormFill]" ,"[TruckID ]= '" & 105 & "' And Month([MonthYr])= #" & 7 & "#"),"False")
Ok, I tried both your suggestions and I get an error of "Data Type Mismatch in Criteria"
The field for this control source is a text box.
'Finalized' is a text field
'TruckID' is a a text field
'MonthYr' is a Date field formatted to "mmm yyyy"
I'm not sure, but I'm positive it's that I'm missing the correct way to enter in the string criteria for the date, this being for the month of July.
I even tried this as an attempt, but got the error message "Syntax error in date in query expression"
=IIf([PrevCurHold]=2,DLook
ASKER
sorry for the confusion, but in my previous post I had 'MileEndLoc' instead of 'Finalized'. I was merely trying another text field. Same results...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This did not work as well. I need to learn more about the uses of ' " & and # !! :-)
=IIf([PrevCurHold]=2,DLook Up("[MileE ndLoc]","[ qryCurYear FormFill]" ,"[TruckID ]= '" & 105 & "' And Month([MonthYr])= '" & 7),"False")
=IIf([PrevCurHold]=2,DLook
ASKER
Thank you MX. I would have never figured that out since I don't quite get the Chr(34) thing.
Did you try my answer?
https://www.experts-exchange.com/questions/22897683/IIF-in-Control-Source.html#20094761
This should have worked too...
https://www.experts-exchange.com/questions/22897683/IIF-in-Control-Source.html#20094761
This should have worked too...
ASKER
I'm very sorry mbizup. I lost track of the posts switching back and forth and totally missed yours, and yes, I just tried your answer and it worked as well.
please ... reopen the question and split the pts with mbiz ...
See this link:
https://www.experts-exchange.com/Community_Support/Community_Advisor/
Chr(34) is just the code for double quotes. I use it for clarity in posting ... eg how many double quotes do you see here:
""'"'"" ?
You get the idea
thx.mx
See this link:
https://www.experts-exchange.com/Community_Support/Community_Advisor/
Chr(34) is just the code for double quotes. I use it for clarity in posting ... eg how many double quotes do you see here:
""'"'"" ?
You get the idea
thx.mx
Community Support General is actually the correct place for re-open requests, etc even though the website does not make that particularly obvious :-)
https://www.experts-exchange.com/Community_Support/General/
> I need to learn more about the uses of ' " & and # !! :-)
Single quotes embedded in strings (or chr(34)'s like mx used) are used to delimit text fields:
,"[TruckID]= '" & 105 & "' And Month([MonthYr])= '" & 7
^ ^
#'s are used to delimit Dates in an Access database (sql server uses ' s):
,"[DateField]= #" & Date() & "# And Month([MonthYr])= '" & 7
Month([MonthYr]) returns a numeric value, so no delimiters were needed there.
https://www.experts-exchange.com/Community_Support/General/
> I need to learn more about the uses of ' " & and # !! :-)
Single quotes embedded in strings (or chr(34)'s like mx used) are used to delimit text fields:
,"[TruckID]= '" & 105 & "' And Month([MonthYr])= '" & 7
^ ^
#'s are used to delimit Dates in an Access database (sql server uses ' s):
,"[DateField]= #" & Date() & "# And Month([MonthYr])= '" & 7
Month([MonthYr]) returns a numeric value, so no delimiters were needed there.
Closed by Expert recommendation.
Any/all comments invited here or at:
vee_mod@experts-exchange.c om
Any/all comments invited here or at:
vee_mod@experts-exchange.c
I'm learning a lot about "the uses of ' " & and # !!"
:-)
:-)