Results 1 to 7 of 7
  1. #1
    rwahdan1978 is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    57

    Get the highest value form 5 textboxes

    Hi

    I have 5 text boxes were the user will enter numbers and I have a button. When clicking the button I want to check which is the highest value and from which textbox, how to do that?

    text1 = 5
    text2 = 0
    text3 = 2
    text4 = 10
    text5 = 7



    so I will get text4 and value is 10

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,552
    Cycle through the textboxes within a loop.?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,928
    Something like
    Code:
     
    
     Dim I as integer
    dim ctl as control
    
    set cal=text0
    for I=1 to 4
        If me(“text” & I)>ctl  then set ctl=me(“text” & I)
    next i 
    debug.print ctl.name; ctl.value
    in my phone so beware smart quotes

    edit - modified code

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Should that be:

    Set ctl = Me.text1

    For I = 2 To 5
    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.

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,928
    Yes, my mistake - I always try to work from base 0.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,552
    TBF CJ did say 'something like' just to indicate the method, expanding on what I offered.
    If the O/P cannot work from that, then we have a problem.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Join Date
    Jun 2022
    Posts
    28
    If you don't mind instantiating an Excel object, you could use its Application.Max() method.

    Or you could roll your own method that accepts a parameter array, loop through them, and return the largest value.

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

Similar Threads

  1. Replies: 7
    Last Post: 03-30-2021, 08:03 AM
  2. Replies: 2
    Last Post: 08-05-2019, 01:24 PM
  3. Replies: 10
    Last Post: 07-16-2018, 08:00 AM
  4. Replies: 15
    Last Post: 12-22-2016, 12:16 PM
  5. All Textboxes Read-Only on Form
    By cbrsix in forum Programming
    Replies: 5
    Last Post: 04-16-2013, 01:47 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