Calculated Fields - Iif IsAlpha (1 Viewer)

kyoch

Registered User.
Local time
Yesterday, 21:29
Joined
Mar 5, 2014
Messages
58
Hello All,

I have a calculated field which is based off a text field which can contain text values and numeric values. I'd like to add a statement in the criteria which performs some action if the value is text. IsNumeric is not a function I can use in expression builder so I'm thinking of some variation of Left should be used.

Here's what I'm wanting...

Iif(Left([TestResult],1)=alpha,"Pass","Fail")

This way, the calculated field will display pass for any values where the first character is an alpha. I can perform this action fine in a query using Not IsNumeric but I need this calculated field to do it for me.

Any suggestions?
 

pr2-eugin

Super Moderator
Local time
Today, 03:29
Joined
Nov 30, 2011
Messages
8,494
Would this not work for you?
Code:
IIF(IsNumeric(Left([TestResult],1)), "Fail", "Pass")
 

SmallTomato

Registered User.
Local time
Yesterday, 22:29
Joined
Mar 24, 2014
Messages
68
Something like this?

Iif(IsNumeric(TestResult)=TRUE,"Fail","Pass")
 

kyoch

Registered User.
Local time
Yesterday, 21:29
Joined
Mar 5, 2014
Messages
58
IsNumeric is not a valid expression I can use in a calculated field
 

kyoch

Registered User.
Local time
Yesterday, 21:29
Joined
Mar 5, 2014
Messages
58
Try creating a calculated field in a new table real quick. IsNumeric cannot be used in a calculated column!
 

pr2-eugin

Super Moderator
Local time
Today, 03:29
Joined
Nov 30, 2011
Messages
8,494
Try creating a calculated field in a new table real quick. IsNumeric cannot be used in a calculated column!
Calculated field in a table !



You are not supposed to store calculated values in tables. This is breaking one of the fundamental principle of DB Design. Read Allen Browne's take on this issue : http://allenbrowne.com/casu-14.html
 

kyoch

Registered User.
Local time
Yesterday, 21:29
Joined
Mar 5, 2014
Messages
58
I'm using this field in a Temporary Table so it's almost like a query lol.

I have a calculated field in my temporary table then some code which puts the values into a permanent table. So my calculated field just calculates whether something passes or fails then stores "Pass" or "Fail" in a separate table. Every time I load the temporary table the values are deleted and it's requeried.

I might not have explained that well enough but is that still breaking the principle of storing calculated fields in a table?
 

pr2-eugin

Super Moderator
Local time
Today, 03:29
Joined
Nov 30, 2011
Messages
8,494
How is the main table updated from this temporary table? You can use the expression there !
 

kyoch

Registered User.
Local time
Yesterday, 21:29
Joined
Mar 5, 2014
Messages
58
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tResults (ProductName, TestName, LotNumber, TestingDate, Technician, TestResult, PassFail) " _
& "SELECT '" & Forms!fMain.Product & "', tTempTblResult.TestName, """ & Forms!fMain.LotNo & """,#" & Forms!fMain.TestingDate & "#, '" & Forms!fMain.Technician & "', tTempTblResult.TestResult, tTempTblResult.PassFail " _
& "FROM tTempTblResult"
DoCmd.SetWarnings True
 

pr2-eugin

Super Moderator
Local time
Today, 03:29
Joined
Nov 30, 2011
Messages
8,494
You are still storing a Calculation based on another field. Why? You do not need to.
 

kyoch

Registered User.
Local time
Yesterday, 21:29
Joined
Mar 5, 2014
Messages
58
Ok, I guess will revisit the idea of storing that value.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 03:29
Joined
Sep 12, 2006
Messages
15,727
the only thing to beware of, as we have seen in some recent threads, is that certain letters (eg D and E) are legitimate within some number formats - so testing isnumeric may still not filter these out. (and they are hard to dig out by normal means!)
 

pr2-eugin

Super Moderator
Local time
Today, 03:29
Joined
Nov 30, 2011
Messages
8,494
Dave, I have been playing with this. If the argument passed to the IsNumeric function is a String, then E is considered as a String rather than a HEX value. If it is passed as not a Formatted String then it returns True.
Code:
? IsNumeric([COLOR=Red][B]E[/B][/COLOR])
[COLOR=Red][B]True[/B][/COLOR]
? IsNumeric([COLOR=Blue][B]CStr(E)[/B][/COLOR])
[COLOR=Blue][B]False[/B][/COLOR]
? IsNumeric([COLOR=Blue][B]"E"[/B][/COLOR])
[COLOR=Blue][B]False[/B][/COLOR]
However with Number (Numerals 0-9) If you pass them as String they still are validated for Numbers.
Code:
? IsNumeric(2)
True
? IsNumeric(CStr(2))
True
? IsNumeric("2")
True
You always can use a UDF to get the ASCII comparison, with optional inclusion of HEX value.

So given the above scenario, if the OP uses Left$ function as opposed to Left we can be rest assured the return will be a String, so the right result is obtained.

My 2 pennies worth !
 

Users who are viewing this thread

Top Bottom