Results 1 to 8 of 8
  1. #1
    Steven.Allman is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Feb 2010
    Posts
    118

    Cross Reference

    Got a doozy...
    Military Pay Chart
    grade 2 4 6 8
    1 500 1000 1500 2000
    2 600 1050 1600 2200
    3 700 1200 1800 2300
    4 800 1300 1900 2500

    Example here.
    A different query gives me their length of service and pay grade;Query1
    Query 2, I want it to take the results from query 1, and cross reference to give me the value.
    IE; October 2023 person will have 4 years of service and is rank 3, so give me 1200 as a result in my query.
    but Im using a query value AND grade value to return that 1200 and I cant figure out how to create that reference.


    data.accdb

    Any pointers?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Normalize your table?
    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
    Steven.Allman is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Feb 2010
    Posts
    118
    Table Analyzer says unless I manually split my data, that its good.
    I am not positive what this means "normalize"

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by Steven.Allman View Post
    Table Analyzer says unless I manually split my data, that its good.
    I am not positive what this means "normalize"
    You would have a table with fields
    PayID (autonumber)
    PayRank
    PayYear
    PayAmount

    Then you would just DLookUp PayRank = 3 and PayYear = 4 and retrieve a value of 1200 from PayAmount
    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

  5. #5
    Steven.Allman is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Feb 2010
    Posts
    118
    Quote Originally Posted by Welshgasman View Post
    You would have a table with fields
    PayID (autonumber)
    PayRank
    PayYear
    PayAmount

    Then you would just DLookUp PayRank = 3 and PayYear = 4 and retrieve a value of 1200 from PayAmount

    I was trying to get away from having to create this table though.
    What your saying is, im screwed.
    gotta create a new table?

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    No, wait and see if anything else is offered.
    That is how I would do it. Then I could produce your cross reference as a crosstab.

    You could create your own function to locate rank record, then walk the fields until you find the correct year of service.
    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
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You could create a union query to normalize the table, and run your queries against that instead of the actual table. It's a workaround to the non-normalized table you have now. Whatever the analyzer may say, you have a piece of data (years of service) as a field rather than a record. Data shouldn't be part of the structure of the table.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Which pay table should pay be pulled from?

    Suggest including ID in YRS-SERVICE query.

    Adjust Query1:
    Code:
    SELECT ID, SM_Name, [pay-grade], [OCT] AS [October Pay], 
         DLookUp("[" & [OCT] & "]","fy23pay","Grade='" & [pay-grade] & "'") AS Pay
    FROM [YRS-SERVICE];
    Be aware that domain aggregate functions can cause slow performance in query with large datasets. But then so can UNION query.

    There is no query wizard/builder for UNION, must type or copy/paste in SQLView. There is a limit of 50 SELECT. First SELECT defines field names and data types. Here is example of first 3 with your data.

    SELECT ID, Grade, [>2 Yrs] AS Pay, ">2" AS Yrs FROM fy23pay
    UNION SELECT ID, Grade, [2], "2" FROM fy23pay
    UNION SELECT ID, Grade, [3], "3" FROM fy23pay;

    Again, adjust Query1:
    SELECT ID, [YRS-SERVICE].SM_Name, [YRS-SERVICE].[pay-grade], CStr(Nz([YRS-SERVICE]![OCT],0)) AS [October Pay]
    FROM [YRS-SERVICE];

    And Query3 using UNION and Query1:
    SELECT Query1.ID, Query1.SM_Name, Query1.[pay-grade], Query2.Pay
    FROM Query2 RIGHT JOIN Query1 ON (Query2.Yrs = Query1.[October Pay]) AND (Query2.Grade = Query1.[pay-grade]);

    Use whichever approach you prefer.

    Should field [>2 Yrs] actually be [<2 Yrs]. Do you want this pay to show for records that show 0 years?

    Personnel ID 7 does not have pay-grade.

    Strongly advise not to use spaces nor punctuation/special characters in naming convention.
    Last edited by June7; 08-18-2023 at 01:31 AM.
    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. Cross reference ??
    By NiJunge in forum Database Design
    Replies: 5
    Last Post: 08-08-2022, 12:45 PM
  2. cross-reference tables
    By Davide in forum Access
    Replies: 8
    Last Post: 01-20-2022, 05:31 PM
  3. Many to many cross reference table as a subform?
    By craigugoretz in forum Forms
    Replies: 2
    Last Post: 02-07-2015, 01:51 PM
  4. Cross reference
    By Anne in forum Access
    Replies: 9
    Last Post: 09-23-2011, 08:01 AM
  5. Replies: 1
    Last Post: 06-18-2011, 10:00 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