Access 2013 calculated field too complex -
apparently, calculated field way complex. suggest better way accomplish i'm trying do?
goal: value entered in strength field determines value appears in calculated field. in advance help!
[strength] number field [strmod] calculated field
below expression tried build support [strmod] calculated field.
iif([strength]=1,-5, iif([strength]>=2 , [strength]<=3,-4, iif([strength]>=4 , [strength]<=5,-3, iif([strength]>=6 , [strength]<=7,-2, iif([strength]>=8 , [strength]<=9,-1, iif([strength]>=10 , [strength]<=11,0, iif([strength]>=12 , [strength]<=13,1, iif([strength]>=14 , [strength]<=15,2, iif([strength]>=16 , [strength]<=17,3, iif([strength]>=18 , [strength]<=19,4, iif([strength]>=20 , [strength]<=21,5, iif([strength]>=22 , [strength]<=23,6, iif([strength]>=24 , [strength]<=25,7, iif([strength]>=26 , [strength]<=27,8, iif([strength]>=28 , [strength]<=29,9, iif([strength]=30,10,null)
here few suggestions using non-calculated data field type.
update query w/ lookup table
replace calculated field type regular number field [strmod]. create strength lookup table:
strengthvalue | strengthcategory 1 -5 2 -4 3 -4 4 -3 5 -3 6 -2 ... ...
then use table create below update query run in afterupdate
, afterinsert
data macros main table or same events in main table's form.
update maintablename inner join strengthlookup on maintablename.strength = strengthlookup.strengthvalue set maintablename.strmod = strengthlookup.strengthcategory
update query w/o lookup table
replace calculated field type regular number field [strmod] , use update query in afterupdate
, afterevent
events:
update maintablename set maintablename.strmod = iif([strength]=1,-5, iif([strength]>=2 , [strength]<=3,-4, iif([strength]>=4 , [strength]<=5,-3, iif([strength]>=6 , [strength]<=7,-2, iif([strength]>=8 , [strength]<=9,-1, iif([strength]>=10 , [strength]<=11,0, iif([strength]>=12 , [strength]<=13,1, iif([strength]>=14 , [strength]<=15,2, iif([strength]>=16 , [strength]<=17,3, iif([strength]>=18 , [strength]<=19,4, iif([strength]>=20 , [strength]<=21,5, iif([strength]>=22 , [strength]<=23,6, iif([strength]>=24 , [strength]<=25,7, iif([strength]>=26 , [strength]<=27,8, iif([strength]>=28 , [strength]<=29,9, iif([strength]=30,10,null))))))))))))))))
vba logic
replace calculated field type regular number field [strmod]. then, use select case
statement in main table's form's afterinsert
, afterupdate
events:
select case me.strength case 1 me.strmod = -5 case 2 3 me.strmod = -4 case 4 5 me.strmod = -3 case 6 7 me.strmod = -3 case 8 9 me.strmod = -1 case 10 11 me.strmod = 0 case 12 13 me.strmod = 1 ... end select
strictly preference, never work calculated fields in case of database compatibility (i.e., ms access 2007 accdb users) , upsizing scalability programming languages (php, python, vb odbc connections) , other rdms (sql server, mysql).
Comments
Post a Comment