Results 1 to 3 of 3
  1. #1
    jobrien4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    20

    Incremental field on query

    I'm building an application via Access that will allow a user at my company to import a CSV file with hundreds of records, press a button that runs several insert queries which inserts some of those records into our ERP system based on criteria.


    Each record of the insert query must have a unique "Interchange Number" that is historically unique, ie, if I used number 1000 in the insert query yesterday, I would need to use 1001 today.


    I already can find which value to start with using a DMAX() function on the table where you insert the records.I need a way to give each record of a select query a unique value that is +1 from the preceding record.




    When I import the CSV file, I already have Access assigning an Autonumber. The problem is the file can have up to a thousand records a day while I only need to insert maybe 10 each day. If the starting Interchange number was 1001, I would like it to go 1001, 1002, 1003, etc. If I add the Autonumber from the table I imported, it can go 1001, 1050, 1343, based on where that record was on the autonumber when it imported.


    So is there anyway to run a select query and have a field on that query start at 1 and count up by 1 for each record? If I can get that I can code the rest. Any ideas?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,628
    What is the process - you import all thousand records into a table then insert only 10 of those records into another table? The sequence number should be assigned in that second table - the autonumber from the initial import can be ignored. What happens to the other 990 records - deleted?

    An expression using DCount can populate a field with sequential number but you need to consider the maximum value of existing records - doesn't sound easy.
    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
    jobrien4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    20
    Maybe this is where you were getting at with the DCount but someone in another forum answered this. You need a unique number (in the example below Order Number). You create a query that sorts the data by the unique number then use expession:

    You build another query using your query as the source. Bring in all the fields from your query and then an additional calculated field using this:

    RecordNumber: DCount("[OrderNumber]", "YourQueryNameHere", "[OrderNumber]<='" & [OrderNumber] & "'")

    Replace "YourQueryNameHere" with the name of your query. It basically counts the number of records equal to or before it. That way it knows what position it holds within that order. Follow my instructions, look at the data, and let me know if you have any issues.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Incremental Number in a Query
    By jmauldin01 in forum Access
    Replies: 5
    Last Post: 01-01-2014, 01:23 AM
  2. Replies: 7
    Last Post: 05-12-2013, 05:15 AM
  3. Incremental Numbers
    By dr4ke in forum Queries
    Replies: 7
    Last Post: 01-16-2013, 03:46 AM
  4. Incremental Table Updating
    By pyrman in forum Queries
    Replies: 4
    Last Post: 07-23-2012, 11:35 AM
  5. Autonumbers and Incremental Numbers
    By stacies in forum Access
    Replies: 2
    Last Post: 01-27-2012, 02:53 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