Results 1 to 4 of 4
  1. #1
    rlaplume is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    2

    how to retrieve the column name

    I have an Access database with a table that contains 11 fields. The first is a unique ID and the other 10 fields are various numbers. I need to know which of the 10 columns contains the highest number for each row and return the 2 rightmost characters of that column name. I started with the “maximum” function that I found on-line and it works to give me the maximum number in each row, but I need it modified to return the 2 rightmost characters of the column name that contains that number. I’m sure it’s a simple thing, if only I knew what I was doing!


    Code:
    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

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Looks like the function is receiving an array that is populated in another procedure. Unless that array has an element that holds the fieldnames, don't see how you can capture the name in that function.

    The function passes back field value. What do you need the value for? Instead of passing back the value, can pass back the array index and possibly use that in the calling procedure to identify the associated field.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    rlaplume is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    2
    I only started with this function because I knew I would need to find the row with the highest value in the row anyway. I don't actually need to know the value, I just need to know the column name (or more specifically, the last 2 letters in the column name) so I guess that could be derived from the array index value. Can you show me how I would have a function return that?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Change the function you have to capture and return the array index that has the maximum value. Use another variable in the loop.

    currentVal = FieldArray(I)
    maxIndex = I

    Then return the maxIndex:

    Maximum = maxIndex
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Query does not retrieve all the rows
    By jon80 in forum Access
    Replies: 1
    Last Post: 01-01-2012, 05:30 AM
  2. ADODB Retrieve Value with SQL Help
    By kawi6rr in forum Programming
    Replies: 3
    Last Post: 05-07-2011, 02:03 PM
  3. Retrieve Data Too Slow
    By BGF in forum Programming
    Replies: 8
    Last Post: 09-08-2010, 04:28 PM
  4. Search and Retrieve
    By sadath in forum Access
    Replies: 3
    Last Post: 07-02-2010, 04:54 AM
  5. Retrieve similar records
    By dodell in forum Queries
    Replies: 3
    Last Post: 03-31-2010, 11:48 AM

Tags for this Thread

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