?
Solved

dmax error

Posted on 2004-11-16
6
Medium Priority
?
359 Views
Last Modified: 2008-01-09
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/
0
Comment
Question by:mc7560
4 Comments
 
LVL 34

Accepted Solution

by:
flavo earned 252 total points
ID: 12599414
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
 
LVL 16

Assisted Solution

by:GreymanMSC
GreymanMSC earned 248 total points
ID: 12599720
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
 

Author Comment

by:mc7560
ID: 12599843
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
 
LVL 51

Expert Comment

by:Steve Bink
ID: 14142825
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question