INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Convert Access Expression to VBA formula

Convert Access Expression to VBA formula

(OP)
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?

RE: Convert Access Expression to VBA formula

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 

RE: Convert Access Expression to VBA formula

(OP)
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!!

RE: Convert Access Expression to VBA formula

Quote:

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])

RE: Convert Access Expression to VBA formula

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.

RE: Convert Access Expression to VBA formula

(OP)
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.

RE: Convert Access Expression to VBA formula

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 (BegTax = 0 And taxIncSub = 0) Or TRQN < Distribution Then 
... 

Have fun.

---- Andy

There is a great need for a sarcasm font.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close