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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expressions Editions Nightmare

Status
Not open for further replies.

rafal444

Programmer
Aug 11, 2006
74
0
0
US
I am writing queries with some complex IIF statements. I find it very difficult to edit and read those Expressions in Access Editor.

Is there any other/better Editor I can use to edit those statements? Here is a sample:

Domestic HV Distribution Expenses Calculated: IIf(IsNull([Total Distribution Expenses]),IIf(IsNull([Domestic Distribution Expenses]),Nulltozero([Domestic HV Distribution Expenses]),([Domestic Distribution Expenses])*IIf(NullToZero([Domestic Revenues])=0,0,NullToZero([Domestic HV Gross Revenue])/[Domestic Revenues])),IIf([Dom HV Deals].[HVDeal]="Royalty",DMax("[Edited Expenses]","[Imputed HV Expenses]","[Gross Revenues] <= " & NullToZero([Domestic Distribution Expenses])),([Total Distribution Expenses])*(IIf(NullToZero([Total revenues])=0,0,NullToZero([Domestic HV Gross Revenue])/[Total Revenues]))))
 
Maybe this helps,
Sometimes I use notepad to give the code a simple layout to keep track of the number of nestings and brackets, then paste it into the access expression builder, like:

IIF(variable = ??,expression,
IIF(variable2 = ??, expression,

and so on..
then paste it into the expression builder of Access (who will elimate the formatting), if you have an error correct in the notepad-version, and try again.


Pampers [afro]
Just back from holiday...
that may it explain it.
 
Yes, you are right. It just would be nice to have it in Accesss...
 
How are ya rafal444 . . .

When an if statement starts getting this complex I'll return the value thru a function in VBA using an [blue]If...Then...Else[/blue] Statement.
Code:
[blue]Domestic HV Distribution Expenses Calculated:FunctionName()[/blue]
Is certainable more readable as well as the [blue]If...Then...Else[/blue] Statement in VBA . . . ;-)

Calvin.gif
See Ya! . . . . . .
 
I am moving stuff to VBa code, how can I reference other query fields in VBA code? Here is an example:

Domestic HV Distribution Expenses Calculated: IIf(IsNull([Total Distribution Expenses]),IIf(IsNull([Domestic Distribution Expenses]),Nulltozero([Domestic HV Distribution Expenses]),([Domestic Distribution Expenses])*IIf(NullToZero([Domestic Revenues])=0,0,NullToZero([Domestic HV Gross Revenue])/[Domestic Revenues])),IIf([Dom HV Deals].[HVDeal]="Royalty",DMax("[Edited Expenses]","[Imputed HV Expenses]","[Gross Revenues] <= " & NullToZero([Domestic Distribution Expenses])),([Total Distribution Expenses])*(IIf(NullToZero([Total revenues])=0,0,NullToZero([Domestic HV Gross Revenue])/[Total Revenues]))))

How would you write this in VBA?
 
rafal444 . . .

Setup the function with arguements to receive the query fields:
Code:
[blue]Public Function FunctionName(DomesticHVDistributionExpensesCalculated, TotalDistributionExpenses)
   [green]your code here[/green]
End Function[/blue]
The custom field in the query would look like:
Code:
[blue]Domestic HV Distribution Expenses Calculated:FunctionName([Domestic HV Distribution Expenses Calculated], [Total Distribution Expenses])[/blue]
[purple]You also have a good example of how a long naming convention can make code hard to read![/purple]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top