Results 1 to 9 of 9
  1. #1
    markarmer is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    14

    Populate 2nd Text box based on Value of Another

    I have a form which is essentially being used as a calculator...

    On the form there are 2 text boxes named txtInput and txtOutput.
    The basis of the boxes are to display an answer in txtOutput based on a number the user puts in txtInput...

    There is no real calculation performed as I need to give a fixed answer based on what the user types in, for example:

    If the user types a number between 1 and 5 in txtInput I need txtOutput to show 23
    If the user types a number between 5 and 10 in txtInput I need txtOutput to show 34
    If the user types a number between 12 and 20 in txtInput I need txtOutput to show 79
    so on and so forth...



    I need to be able to set the returned values as as I said, they can't be calculated. It will be tedious but I only need to put the values in for 35 different options so it won't be too bad, I just can't figure out how to have the txtInput use what is entered in it to pull up the right answer.

    Essentially it is like an IF query, but with multiple options for the IF.

    Any help with this would be greatfully appreciated, and thank you in advance.

  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,521
    It's certainly possible; you'd use the after update event of the input textbox, along with Select/Case. Personally though, I'd put the values in a table with 3 relevant fields: the upper and lower limits plus the value to return. Then you can use DLookup() or a recordset to retrieve the appropriate value. That makes it more maintainable than having it all in code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2007
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Simple If Then ElseIF Then

    Me.txtInput
    If Me.txtInput >= 1 And Me.txtInput < 5 Then
    Me.txtOuput = 23
    ElseIf Me.txtInput >= 5 And Me.txtInput < 10 Then
    ...
    Else
    ...
    End If

    Not sure how to use Select Case with a range. Could input values be like 4.78?
    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.

  4. #4
    markarmer is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    14
    Unfortunately yes, the user will be inputting a number with 2 decimal places following, eq. 7.55

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by June7 View Post
    Not sure how to use Select Case with a range.
    Case 1 To 5
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    markarmer is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    14
    Thank you both...
    I ended up using the select case and it does all I need for this purpose.

    Thank you again

    Mark

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

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2007
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Could be issue with Select Case when ranges are like 1 to 5, 5 to 10. Is this syntax inclusive of the end values? Which range does 5 belong with? That's why I asked if values could be other than whole numbers. Can't do 1 to 4, 5 to 10 because that would not capture the mixed numbers.
    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.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Only the OP can address their situation, but in your example the number 5 would get the first value (from the 1-5 test). Code will drop out of the Select/Case as soon as a condition is met, so the second (5-10) test would never be executed.
    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. Populate a field based on combobox selection
    By rscott7706 in forum Access
    Replies: 5
    Last Post: 06-02-2011, 03:18 PM
  2. Replies: 15
    Last Post: 04-01-2011, 11:41 AM
  3. populate boxes based on combo box choice
    By Mattm1958 in forum Forms
    Replies: 13
    Last Post: 08-30-2010, 02:09 PM
  4. Populate one field based upon another fields data
    By BigBrownBear in forum Queries
    Replies: 1
    Last Post: 03-23-2010, 04:27 PM
  5. Replies: 3
    Last Post: 10-05-2009, 07:22 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