Display Record Number In Query

I have a basic query on a table

SELECT Mnemonic, Name, Type
from tbl1

I want to be able to display the row number within the query where the
result would be

1 AB NAME1 TYPE1
2 BC NAME2 TYPE2


How do I accomplish this?

2 Comments

  1. Re: Display Record Number In Query by Douglas J Steele

    Douglas J Steele 2009-10-21

    Assuming Mnemonic is the primary key of the table, you could use:

    SELECT DCount("*", "tbl1", "Mnemonic <= '" & Mnemonic & "'") AS RowNumber,
    Mnemonic, [Name], [Type]
    FROM tbl1
    ORDER BY Mnemonic

    Note, though, that it'll be slow.

    Also, just in case those are the real field names, Name and Type should be
    changed to non reserve words. For a comprehensive list of names to avoid (as
    well as a link to a free utility to check your application for compliance),
    see what Allen Browne has at http://www.allenbrowne.com/AppIssueBadWord.html

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "samuel" <samuel@discussions.microsoft.com> wrote in message
    news:4FAA8836-86D2-487E-BD0D-F9D2DA27141B@microsoft.com...
    I have a basic query on a table

    SELECT Mnemonic, Name, Type
    from tbl1

    I want to be able to display the row number within the query where the
    result would be

    1 AB NAME1 TYPE1
    2 BC NAME2 TYPE2


    How do I accomplish this?

  2. Re: Display Record Number In Query by UtfBUyDbGFyaw

    UtfBUyDbGFyaw 2009-10-21

    http://www.eggheadcafe.com/software/aspnet/30963421/add-a-sequential-number-t.aspx

    "samuel" wrote:

    I have a basic query on a table

    SELECT Mnemonic, Name, Type
    from tbl1

    I want to be able to display the row number within the query where the
    result would be

    1 AB NAME1 TYPE1
    2 BC NAME2 TYPE2


    How do I accomplish this?