473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Data Type Mismatch in an IIf function

Hello, and thanks in advance for any advice.

I can run the following IIf statements without issue independently , but when I combine them together I get a "Data Type Mismatch" error. Here are the separate statements:

Expand|Select|Wrap|Line Numbers
  1. Exp1: IIf([Tot_Hours]>=24,[Wgt_Time],"")
  2.  
  3. Exp2: IIf(([On_TG]<=[To_TG]) And ([On_TG]<=12 And [To_TG]>=12),[Wgt_Time],"")
Here's what they look like when combined:

Expand|Select|Wrap|Line Numbers
  1. CombExp: IIf([Tot_Hours]>=24,[Wgt_Time],IIf(([On_TG]<=[To_TG]) And ([On_TG]<=12 And [To_TG]>=12),[Wgt_Time],""))
Descriptions of the values in the expressions are as follows:
Tot_Hours is a DateDiff("h") on two dates, and formatted as a general number
On_TG and To_TG are both DatePart("h) of two different dates, and formatted as a general number
Wgt_Time: 1/([Tot_Hours]+1)

Again, appreciate the assistance.
Apr 28 '11 #1
12 7380
pod
298 100+
I have had similar problems sometimes, but they were due to some residual code I could not see in the Control Source field. Make sure you clean out that field completely, then start fresh, if you have a line break character in there it might buck.

I could not try your code but if your two seperate functions are working, it looks good.

I suggest start with the first one, make it work again, then add the second one but making the variables constant values:
Expand|Select|Wrap|Line Numbers
  1. IIf([Tot_Hours]>=24,[Wgt_Time],IIf((12<=12) And (12<=12 And 12>=12),[Wgt_Time],""),""))
if it works, change one variable at a time and assess from there
Apr 28 '11 #2
NeoPa
32,556 Expert Mod 16PB
Jon, interesting question and well laid out. I've looked at your three expressions very carefully and I have to say I don't see any divergence or reason for the third one to fail. I would suggest that each of the comparison expressions is contained in parentheses (as below), but this is common between expressions two and three so I hold little hope it will resolve your issue.
Expand|Select|Wrap|Line Numbers
  1. CombExp: IIf([Tot_Hours]>=24,[Wgt_Time],IIf(([On_TG]<=[To_TG]) And ([On_TG]<=12) And ([To_TG]>=12),[Wgt_Time],""))
Generally, in situations like this, I find the answer lies in something different somewhere else that you don't comment on simply because you're totally unaware of what it is. This can only really be found by looking at the whole database.
Apr 29 '11 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Tot_Hours is a DateDiff("h") on two dates, and formatted as a general number
On_TG and To_TG are both DatePart("h) of two different dates, and formatted as a general number
Wgt_Time: 1/([Tot_Hours]+1)
Just to be clear, are they also STORED as a number, or merely formated as one?
Apr 29 '11 #4
Good question re: stored vs. formatted. Probably just formatted.

Those values are derived from date fields, and I used the properties to format to general number.

How do I store them as numbers instead of only formatting them?
Apr 29 '11 #5
TheSmileyCoder
2,322 Expert Mod 2GB
Well DateDiff returns a long, and DatePart returns a Integer, so unless you have since used a FORMAT function (which returns a string!) then I don't think that should give trouble.


Are the fields in question fields in a query or in a table? If in a table, what is the type of the field? Text, numeric, or date/Time?
Apr 29 '11 #6
The fields are in the query, but are derived from fields in the same query that come from a ODBC connection to an oracle DB table and those are date/time.
Apr 29 '11 #7
TheSmileyCoder
2,322 Expert Mod 2GB
Sorry, but Im am simply all out of ideas/suggestions.
Apr 29 '11 #8
No problem, thanks for the brain power though. At least this is validating...since I was going crazy trying to correct it thinking that there was something obvious I wasn't looking at.

Good to know that at least it isn't a newb issue, as I'm relatively new to working in Access.
Apr 29 '11 #9
TheSmileyCoder
2,322 Expert Mod 2GB
Can you test whether you get the error specifically when the second IIF is true (returning [Wgt_Time]) or when it is false (returning "")?

Do all rows have a non-Null value of [Wgt_Time]?
Apr 29 '11 #10
There are no null values, but I did notice that some have negative values.

I figured it wouldn't be the issue though since it runs successfully when it isn't being combined with the first IIF expression.
Apr 29 '11 #11
Just a quick follow up to close this out...

Instead of trying to edit my existing query, I started over with a new one and the expressions work.
May 4 '11 #12
pod
298 100+
... residual code or character syndrome, I call it :)
May 4 '11 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Laurel | last post by:
this is driving me crazy. i need to use a form control as a criteria in a select query, and the control's value is set depending upon what a user selects in an option group on the form. the query...
3
by: Martin Lacoste | last post by:
Is there some issue with using too many left/right/mid/len functions in queries? Depending on the usage, they work fine, but... then there's here: SELECT Master_CAO.Incipit,...
4
by: N J | last post by:
Hi, CurrentDb.Execute "Update tblDelayedOrders Set DELAYED = True Where ID = " & Me.txtOrderNumber & ";", dbfailonerror Me.StatusListBox.AddItem "ORDER # " & Me.txtOrderNumber & " MARKED AS...
3
by: martlaco1 | last post by:
Trying to fix a query that (I thought) had worked once upon a time, and I keep getting a Data Type Mismatch error whenever I enter any criteria for an expression using a Mid function. Without the...
2
by: igor.barbaric | last post by:
Hello! I have created a very simple query like this: SELECT Tasks.Name, DurationHrs(,) AS Duration FROM Tasks INNER JOIN Log ON Tasks.TaskID=Log.TaskID; The above query works fine....
1
by: lalbee | last post by:
I am trying to use the Dcount function but receive a data type mismatch error, can someone help me determine the cause? Count: DCount("","qry-final everhome results"," <'0' ") Thanks!
6
by: christianlott1 | last post by:
Taken (and modded) from http://www.codeguru.com/vb/gen/vb_misc/tips/ article.php/c13137 'RESULTS' table: REF_STRING - TEXT 250 TEST_STRING - TEXT 250 MATCH_VALU - SINGLE FIXED 2 DECIMAL...
2
by: psychomad | last post by:
Please, can someone help me out to solve this error, i've been searching throughout my codes and yet i didnt succeed in finding the error!!!! The Error is: Server Error in '/' Application....
19
by: Lysander | last post by:
I have written a query that takes three integers representing day,month and year, forms a date from them and compares this date to the date the record was entered and returns any records where the...
2
by: hype261 | last post by:
So I have a SQL Query I am trying to author and it keeps giving me a Data Type mismatch error which I can't seem to see. Exact error message is Data type mismatch in criteria expression. Here is...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.