dmax error

Experts, All of the fields following me. are txt fields in my form, based on which the vba runs off of. When I run the code, I get an error message.

dhrsleft = IIf((DMax(Me.hdev, Me.ddev) - Me.dev) > 0, (DMax(Me.hdev, Me.ddev) - Me.dev), 0)

I am trying to determine the maximum value between hdev & ddev and use that to calculate the variance between that and dev. For example:
if hdev = 10, ddev= 15 and dev= 10 then I want the dhrsleft = max(10,15)-10 = 5

Please help/
mc7560Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

flavoCommented:
You cant use dmax to do this, its not the same as Excel's Max function (infact there isnt any Access function that does it.

Use this

IIf(Me.hdev > Me.ddev, Me.hdev, Me.ddev) - Me.dev
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GreymanMSCCommented:
DMax(Range, Domain) returns the maximum value of the field named Range in table named Domain.
It does not compare the values of the parameters, it uses them to run a query and return the result.  
 
For example: DMax("Cost", "SaleItems").  The query would be:  Select Max(Cost) from SaleItems;
 
PS: A third and optional parameter, the Criteria, filters the selection.
0
mc7560Author Commented:
Oh- that explains the value that I've been getting. Instead of using the if statement, if I wanted to write a public funtion that looked at the value of two fields, how would I create the function?
0
Steve BinkCommented:
Do not accept this as a solution.

Public Function MyMax(var1, var2)

MyMax = IIF(var1 > var2, var1, var2)

End Function

In your query/report

=MyMax(hdev, ddev)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.