Results 1 to 5 of 5
  1. #1
    Scorpio11 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2010
    Location
    Cape Town, ZAR
    Posts
    36

    Question Lookup of result based on 1 value compared to range.

    Hi

    I am having a issue with lookups and all the sites that i can see don't seem to deal with it the way i am wanting to

    I want to perform a look up on based on a number and i want it to pull a record based on a range.

    Eg: Value i have = 22 is in 1 table and i want it to find the record based on the range that starts at 21 and ends at 30 out of the following range of records and give me the result C that exists in another table

    ID Start End Result
    1 0 10 A
    2 11 20 B


    3 21 30 C
    4 31 40 D

    My problem is that i cannot figure out how to do this, queries seem obvious, but i cannot program it properly. SQL also does not seem to help me (although i am hardly an expert at it). VBA would seem the best, but i have no idea how to code.

    All the usual sources of looks up deal with combo boxes or linking tables together. But those rely on precise lookups. I am needing an imprecise lookup based on range.

    Thoughts, comments, suggestions all welcome.

    Thanks - Scorp

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Try:

    DLookup("Result", "tablename", criteria input & " BETWEEN Start AND End")

    Trick is capturing the criteria input. It can be reference to another field of a query or to a textbox on a form.
    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
    Scorpio11 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2010
    Location
    Cape Town, ZAR
    Posts
    36
    Hi,

    I created a VBA code with your Dlookup suggestion, i just put in my tables and cells now. I put it in a button so when i click it, the result is produced.

    My exact code is:

    Me!SearchResult = DLookup("TestRes", "tblLookup", criteria input & " BETWEEN TestValSt AND TestVal")

    I am getting an error though:

    Compile Error
    Expected: list separator or )

  4. #4
    Scorpio11 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2010
    Location
    Cape Town, ZAR
    Posts
    36
    Never Mind, I have just figured it out, just made an ass of myself

    Me!SearchResult = DLookup("TestRes", "tblLookup", SearchString & " BETWEEN TestValSt AND TestVal")

    I just realised that I was not comparing it to anything,

    Thanks a mil.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Need something in place of 'criteria input' for user input. This could be reference to control on form or an InputBox function call or a field in query.

    Instead of VBA code could put the expression in a query to create a field or in ControlSource of textbox. The 'criteria input' would be the field that has value 22.

    Okay, you figured that out while I was posting.
    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. Replies: 3
    Last Post: 09-09-2015, 03:11 PM
  2. SUM based on date range in query builder
    By tjstromquist in forum Queries
    Replies: 1
    Last Post: 04-04-2012, 09:07 AM
  3. Query Date Range Based on Calculated Fields
    By wilsoa in forum Queries
    Replies: 6
    Last Post: 03-08-2012, 02:41 PM
  4. joins based on date range
    By broecher in forum Database Design
    Replies: 4
    Last Post: 11-04-2011, 06:32 PM
  5. Query result based upon two field conditions
    By diane802 in forum Access
    Replies: 35
    Last Post: 01-08-2010, 06:31 PM

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