Need to find maximum value

P

pokdbz

I need to find the maximum value of 2 items in a text box. How doe the Dmax
work. I can't seem to get it to work.
 
B

Brendan Reynolds

If the two items are in one text box, what is the delimiter, i.e. what
separates one value from the other?

For example, if the two items were delimited by a space ...

2.3 1.2

.... the following expression would return the maximum of the two ...

=IIf(Val(Left$([Text0],InStr([Text0],"
")-1))<Val(Mid$([Text0],InStr([Text0]," ")+1)),Mid$([Text0],InStr([Text0],"
")+1),Left$([Text0],InStr([Text0]," ")-1))

Replace "[Text0]" with the name of your text box, and the space (" ") with
your delimiter.

The DMax function retrieves the maximum value from a table or query, it
won't help with a text box.
 
D

Douglas J Steele

DMax doesn't work on text boxes: it works on tables (or queries).

To get the max value of two text boxes, try something like:

IIf(Me.Text1 & "" > Me.Text2 & "", Me.Text1, Me.Text2)
 
B

Brendan Reynolds

BTW: I should have mentioned that the best solution is not to have two items
in one text box - it's almost always easier to put things together than to
break them apart - at least, it is in the world of relational databases! :)

--
Brendan Reynolds

Brendan Reynolds said:
If the two items are in one text box, what is the delimiter, i.e. what
separates one value from the other?

For example, if the two items were delimited by a space ...

2.3 1.2

... the following expression would return the maximum of the two ...

=IIf(Val(Left$([Text0],InStr([Text0],"
")-1))<Val(Mid$([Text0],InStr([Text0],"
")+1)),Mid$([Text0],InStr([Text0]," ")+1),Left$([Text0],InStr([Text0],"
")-1))

Replace "[Text0]" with the name of your text box, and the space (" ") with
your delimiter.

The DMax function retrieves the maximum value from a table or query, it
won't help with a text box.

--
Brendan Reynolds

pokdbz said:
I need to find the maximum value of 2 items in a text box. How doe the
Dmax
work. I can't seem to get it to work.
 
P

pokdbz

I ment 2 seperate text boxes. Douglas's suggestion should help me out.

Lynn Trapp said:
What do you mean by "2 items in a text box"?

DMax returns the maximum value of a field in a domain (table or query) based
on some criteria. Here's an example from the Help file.

=DMax("[Freight]", "Orders", "[ShipRegion] = 'CA'")

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm
Jeff Conrad's Access Junkie List:
http://home.bendbroadband.com/conradsystems/accessjunkie.html



pokdbz said:
I need to find the maximum value of 2 items in a text box. How doe the
Dmax
work. I can't seem to get it to work.
 
P

pokdbz

So what is the result of this? So will the result just be a number or will
it be text1 or text2
 
D

Douglas J Steele

Me.Text1 and Me.Text2 return the value that's currently stored in the text
box.

The result will be the number.

Actually, if you're dealing with numbers, you might want to use:

IIf(Nz(Me.Text1, -999) > Nz(Me.Text2, -999), Me.Text1, Me.Text2)

That assumes -999 is smaller than the smallest legitimate value.
 
L

Lynn Trapp

Ah, I see. To paraphrase a famous commercial tag line, "Your in good hands
with Doug Steele."

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm
Jeff Conrad's Access Junkie List:
http://home.bendbroadband.com/conradsystems/accessjunkie.html



pokdbz said:
I ment 2 seperate text boxes. Douglas's suggestion should help me out.

Lynn Trapp said:
What do you mean by "2 items in a text box"?

DMax returns the maximum value of a field in a domain (table or query)
based
on some criteria. Here's an example from the Help file.

=DMax("[Freight]", "Orders", "[ShipRegion] = 'CA'")

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm
Jeff Conrad's Access Junkie List:
http://home.bendbroadband.com/conradsystems/accessjunkie.html



pokdbz said:
I need to find the maximum value of 2 items in a text box. How doe the
Dmax
work. I can't seem to get it to work.
 
Top