Results 1 to 6 of 6
  1. #1
    tennisbuck is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2012
    Posts
    51

    Help! Selecting the lowest value in a row

    Good Morning-

    If I had a query structered like this:


    Part Number Suppplier A Supplier B Supplier C Chose this supplier/Price
    100 $50.00 $60.00 $55.00 ?

    How could I create a column that would either chose the supplier's name or price as the lowest optioin? I know how to do conditional formatting in excel or min function but can't figure this out in Access.

    Mike

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    The table isn't normalized, but:

    Minimum or Maximum Value Across Fields of Record
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    tennisbuck is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2012
    Posts
    51
    Thanks. So what do I need to change in this code?

    Function Minimum(ParamArray FieldArray() As Variant)
    ' Declare the two local variables.
    Dim I As Integer
    Dim currentVal As Variant

    ' Set the variable currentVal equal to the array of values.
    currentVal = FieldArray(0)

    ' Cycle through each value from the row to find the smallest.
    For I = 0 To UBound(FieldArray)
    If FieldArray(I) < currentVal Then
    currentVal = FieldArray(I)
    End If
    Next I

    ' Return the minimum value found.
    Minimum = currentVal

    End Function

    Function Maximum(ParamArray FieldArray() As Variant)
    ' Declare the two local variables.
    Dim I As Integer
    Dim currentVal As Variant

    ' Set the variable currentVal equal to the array of values.
    currentVal = FieldArray(0)

    ' Cycle through each value from the row to find the largest.

    For I = 0 To UBound(FieldArray)
    If FieldArray(I) > currentVal Then
    currentVal = FieldArray(I)
    End If
    Next I

    ' Return the maximum value found.
    Maximum = currentVal

    End Function
    Table: tblMinMax
    ---------------------------
    Field Name: Field1
    Data Type: Number
    Field Size: Long Integer

    Field Name: Field2
    Data Type: Number
    Field Size: Long Integer

    Field Name: Field3
    Data Type: Number
    Field Size: Long Integer

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Nothing, you just copy the function into a standard module and call it from wherever it's needed.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    tennisbuck is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2012
    Posts
    51
    Thanks! It worked perfect.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    No problem!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Using expression builder to find lowest date
    By MMcKenna in forum Queries
    Replies: 1
    Last Post: 03-20-2012, 02:28 PM
  2. How to pull lowest value?
    By TommyRex in forum Access
    Replies: 5
    Last Post: 10-25-2010, 02:09 PM
  3. Selecting next set of control No's
    By newtoAccess in forum Queries
    Replies: 0
    Last Post: 02-28-2010, 10:28 AM
  4. Query to find lowest value
    By AccessNubie in forum Access
    Replies: 3
    Last Post: 11-30-2009, 07:54 AM
  5. Replies: 1
    Last Post: 10-06-2009, 02:00 AM

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