Link to home
Start Free TrialLog in
Avatar of wilcon
wilcon

asked on

Searching to a Microsoft Access Dataset using VBA

How do I search through a Microsoft Access Dataset using VBA to find the greatest value
Avatar of pweegar
pweegar

take a look at the max function. Also look at dmax.
ASKER CERTIFIED SOLUTION
Avatar of sagacitysolutions
sagacitysolutions
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Using DMax:
Dim MaxVal as variant

MaxVal = DMax("YourField", "YourTable")
Are really talking about a "DataSet"  i.e. a .NET object?

If so, then the following will do the trick

dsMyDataSet.tables("MyTable").DefaultView.Sort = "MyField"
dim dr as datarow = dsMyDataSet.Tables("MyTable").DataView.Rows(0)

Not sure I understand why you would choose to use 6 lines of code and overhead when you can do the same thing with 1 line of code.  That's very inefficient.
Arji,

I think it was accepted, because it was a complete example.

Im just here to help, if you want the points thats fine with me.
Don't care about the points....just thought it was a little strange.  It is the asker's right to choose whatever answer he wants especially since you answered first and it WAS a correct answer.  I would only object if my answer was first and correct and the asker chose something submitted after my answer....no problem...just curious.