Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I think you can do this thing in VBA code instead of in a query with function.

    or

    modify the maximum function to use sample id as the parameter, and look for the max field:


    Code:
    Public Function MaxField(pKeyValue As Variant) As Double
        Const tblName = "mytable"
        Const pKey = "sample"
        Const FieldList = "f2,f3,f5"
        
        Dim rs As DAO.Recordset
        Dim keystr As String
        Dim i As Long
        If VarType(pKeyValue) = vbString Then
            keystr = pKey & "='" & pKeyValue & "'"
        Else
            keystr = pKey & "=" & pKeyValue
        End If
        Set rs = CurrentDb.OpenRecordset("select " & FieldList & " from " & tblName & " where " & keystr)
        If Not rs.EOF Then
            MaxField = -100000000#
            For i = rs.Fields.Count - 1 To 0 Step -1
                If MaxField < rs.Fields(i).Value Then MaxField = rs.Fields(i).Value
            Next
        Else
            MaxField = Null
        End If
    End Function

  2. #17
    megabrown is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2010
    Posts
    18
    There we go, here's a sample of the db.

    Sweet, Ill try the modified max function

  3. #18
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I think you're hitting the character limit for the query grid. I didn't want to go the way of a custom function if I could get away with it, but it looks like you'll have to go that way. Try weekend's and see how it goes. Off the top of my head it looks okay except for this:

    MaxField = Null

    which will error due to the Double data type.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #19
    Dawmah is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    2
    hi Paul.
    I need a code or query that will calculate the two most high values within a record still over different fields.Actually I choose out of four values.

  5. #20
    Dawmah is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    2

    Red face top two values across field

    I need a code or query that will return the two most high values within a record still over different fields.Actually I choose out of four values.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Selecting Dates
    By jpalk in forum Queries
    Replies: 3
    Last Post: 05-21-2010, 06:08 AM
  2. Selecting between two dates
    By nicorvp in forum Queries
    Replies: 5
    Last Post: 05-04-2010, 08:17 AM
  3. Selecting Just One Name Type
    By susan in forum Queries
    Replies: 1
    Last Post: 12-03-2009, 12:08 PM
  4. Finding highest value in a text field
    By cdominguez in forum Queries
    Replies: 3
    Last Post: 06-02-2009, 09:39 AM
  5. query to find the highest value in a field
    By jhjarvie in forum Queries
    Replies: 0
    Last Post: 09-02-2008, 02:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums