Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Access Expression to VBA formula 1

Status
Not open for further replies.

Tia77

MIS
May 11, 2017
6
US
GainRecDistr: IIf([BegTaxBasis]=0 And [Contribution]+[Distribution]=0,0,IIf([BegTaxBasis]=0 And [TaxIncSubTotal]=0,-[Distribution],IIf([Distribution]=0,0,IIf([TBBLL]>0,0,IIf([TBBLL]+[Recourse]+[QualifiedNonrecourse]+[NonRecourse]<[Distribution],-[Distribution],IIf([TBBLL]+[Recourse]+[QualifiedNonrecourse]+[NonRecourse]>[Distribution] And [TBBLL]+[Recourse]+[QualifiedNonrecourse]+[NonRecourse]<0 And [TaxIncSubTotal]<0,[TBBLL]+[Recourse]+[QualifiedNonrecourse]+[NonRecourse]-[TaxIncSubTotal],[TBBLL]+[Recourse]+[QualifiedNonrecourse]+[NonRecourse]))))))

when I try to calculate the above in access expression it gives me an error message saying query is too complex specifically the problem is with this section:

IIf([TBBLL]+[Recourse]+[QualifiedNonrecourse]+[NonRecourse]>[Distribution] And [TBBLL]+[Recourse]+[QualifiedNonrecourse]+[NonRecourse]<0 And [TaxIncSubTotal]<0,[TBBLL]+[Recourse]+[QualifiedNonrecourse]+[NonRecourse]-[TaxIncSubTotal],[TBBLL]+[Recourse]+[QualifiedNonrecourse]+[NonRecourse]))))))

How can I convert this into a VBA expression? Any ideas much appreciated?
 
As already stated make a UDF and use that in the query. What you have is a complete disaster, and I cannot follow it.
Code:
Public Function GetVal(BegTax as variant, Contribution as variant, Distribution as variant, TaxIncSub as variant, TBBLL as variant, recourse as Public Function GetVal(BegTax as variant, Contribution as variant, Distribution as variant, TaxIncSub as variant, TBBLL as variant, recourse as variant, QualifiedNonRecourse as Variant, NonRecourse as variant) as long
  Dim TRQN as long
  TQRN = TBBLL + Recourse + QualifiedNonRecourse + NonRecourse
  if BegTax = 0 and taxIncSub = 0  or TRQN < Distribution then 
     getVal = - Distribution
  elseif (TRQN > Distribution and TRQN <0) and TaxIncSub<0 then
     getVal = TRQN - TaxIncSub
  else
     getVal = TRQN
  end if
end function
 
oh wow that is really helpful thank you!! Can you by chance help me with the first section as well I want to convert that into VBA IF- Then's:

IIf([BegTaxBasis]=0 And [Contribution]+[Distribution]=0,0,IIf([BegTaxBasis]=0 And [TaxIncSubTotal]=0,-[Distribution],IIf([Distribution]=0,0,IIf([TBBLL]>0,0,IIf([TBBLL]+[Recourse]+[QualifiedNonrecourse]+[NonRecourse]<[Distribution],-[Distribution],IIf([TBBLL]+[Recourse]+[QualifiedNonrecourse]+[NonRecourse]>[Distribution] And [TBBLL]+[Recourse]+[QualifiedNonrecourse]+[NonRecourse]<0 And [TaxIncSubTotal]<0,[TBBLL]+[Recourse]+[QualifiedNonrecourse]+[NonRecourse]-[TaxIncSubTotal],[TBBLL]+[Recourse]+[QualifiedNonrecourse]+[NonRecourse]))))))

Thanks so much!!
 
Can you by chance help me with the first section as well I want to convert that into VBA
Yeah, that is what I did. Your sql would then be

GainRecDistr:getVal([begTaxBasis],[contribution],[Distribution],[TaxIncSubTotal],[TBBLL],{Recourse],{QualifiedNonRecourse])
 
Code:
Public Function GetVal(BegTax as variant, Contribution as variant, Distribution as variant, TaxIncSub as variant, TBBLL as variant, recourse as variant, QualifiedNonRecourse as Variant, NonRecourse as variant) as long
  Dim TRQN as long
  TQRN = TBBLL + Recourse + QualifiedNonRecourse + NonRecourse
  if BegTax = 0 and taxIncSub = 0  or TRQN < Distribution then 
     getVal = - Distribution
  elseif (TRQN > Distribution and TRQN <0) and TaxIncSub<0 then
     getVal = TRQN - TaxIncSub
  else
     getVal = TRQN
  end if
end function

The function looks like a copy and past mistake.
 
wow you are honestly a genius...I was barely able to understand my own crazy IF's and somehow you made sense of it and got it to work.. amazing much appreciated.
 
MayP does fantastic job.
I would just add a couple of parenthesis just because I can never remember the Operator Precedence of Logical Operators:

Code:
...
If [blue]([/blue]BegTax = 0 And taxIncSub = 0[blue])[/blue] Or TRQN < Distribution Then 
...

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top