Results 1 to 14 of 14
  1. #1
    rmoreno is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Apr 2013
    Posts
    51

    Access Data (VLOOKUP function?)

    Hi all. I’m having difficulty trying to figure out how to do this.

    I have a query [qry_GRADENUM] with a field name [GRADE] that has a number from 0 to 9.


    I also have a table [tbl_GRADELIST] that has 10 columns with data.

    What I need is to somehow link the qry_GRADENUM.[GRADE] number to the correct column in the [tbl_GRADELIST] table.
    It would be great if Access had an OFFSET function but it doesn't. Does anyone have a suggestion on how I can do this?
    Attached Thumbnails Attached Thumbnails GradeListStructure.jpg  

  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,643
    In a relational database, the GradeList table would have 3 fields and look like:

    Code:
    GradeLst   Grade   Description
    Test           0         No Action
    Test           1         Contact Me
    From there it's a simple lookup with GradeLst and Grade as criteria.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    rmoreno is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Apr 2013
    Posts
    51
    I agree, however, the GradeLst table format is fixed and cannot be changed. I have to work with what is already there.

  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,643
    Then I would probably create a UNION query that "normalized" the data, and use that in queries or for lookups.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    rmoreno is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Apr 2013
    Posts
    51
    OK, how do I do that. Can you show me an example please?

  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,643
    Along the lines of:

    SELECT GradeLst As GradeType, 0 As Grade, Grade0 As Description
    FROM GradeList
    UNION ALL
    SELECT GradeLst As GradeType, 1 As Grade, Grade1 As Description
    FROM GradeList
    ...
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    rmoreno is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Apr 2013
    Posts
    51
    I tried using the code you suggested and I am getting an error message: "The syntax of the subquery in this expression is incorrect"
    What am I doing wrong?

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    From the sound of it, you added it in the design grid somewhere. Get a new query into SQL view and type it there. The design grid does not support UNION queries.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    rmoreno is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Apr 2013
    Posts
    51
    Did that. Now I get the error: Syntax error in query. Incomplete query clause.

    I guess I don't really understand what and how a UNION query works. Could you please explain?

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    You didn't include the ellipsis did you? Does this work?

    SELECT GradeLst As GradeType, 0 As Grade, Grade0 As Description
    FROM GradeList
    UNION ALL
    SELECT GradeLst As GradeType, 1 As Grade, Grade1 As Description
    FROM GradeList
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    rmoreno is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Apr 2013
    Posts
    51
    Here is my code:
    SELECT GradeLst As GradeType, 0 As Grade, Grade0 As Description FROM GradeList
    UNION ALL SELECT GradeLst As GradeType, 1 As Grade, Grade1 As Description FROM GradeList
    SELECT GradeLst As GradeType, 2 As Grade, Grade2 As Description FROM GradeList
    SELECT GradeLst As GradeType, 3 As Grade, Grade3 As Description FROM GradeList
    SELECT GradeLst As GradeType, 4 As Grade, Grade4 As Description FROM GradeList
    SELECT GradeLst As GradeType, 5 As Grade, Grade5 As Description FROM GradeList
    SELECT GradeLst As GradeType, 6 As Grade, Grade6 As Description FROM GradeList
    SELECT GradeLst As GradeType, 7 As Grade, Grade7 As Description FROM GradeList
    SELECT GradeLst As GradeType, 8 As Grade, Grade8 As Description FROM GradeList
    SELECT GradeLst As GradeType, 9 As Grade, Grade9 As Description FROM GradeList;

    It is now giving me a differenct error message: Syntax error in FROM clause.

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    Each SELECT/FROM clause must be separated by UNION ALL, just as I did the first two.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    rmoreno is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Apr 2013
    Posts
    51
    OK. That did it. I can't thank you enough for your expertise and patience with me on this problem.

    I consider this issue SOLVED.

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    Happy to help!
    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. VLookup function in Access?
    By mveda2004 in forum Queries
    Replies: 2
    Last Post: 02-25-2013, 09:42 PM
  2. Simple VLookup function in Access
    By acharyagautam in forum Queries
    Replies: 12
    Last Post: 02-07-2012, 12:18 PM
  3. Query to work as a Vlookup function
    By dharmik in forum Queries
    Replies: 21
    Last Post: 01-04-2012, 08:12 AM
  4. working as a vlookup function
    By cleon in forum Queries
    Replies: 3
    Last Post: 12-16-2011, 02:51 PM
  5. Vlookup function in access
    By rici7 in forum Forms
    Replies: 1
    Last Post: 10-16-2010, 04:41 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