Results 1 to 7 of 7
  1. #1
    JB510's Avatar
    JB510 is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Ontario
    Posts
    42

    How to search by record number?

    I have a database Table with over 600000 lines of data.


    There is a keyed field name "AutoNumber" on the table but many records have been deleted so the AutoNumber is not sequential and sometimes missing large gaps.
    I must process each line differently depending on the value in one of the field names so I must loop though every record one at a time.

    Rather than sucking all records into a single recordset and looping through (this I feel is too large to handle memory wise),
    is there a way to loop one record at a time?

    Ex. The recordset.RecordCount is 600000 but the AutoNumber may be much larger due to deleted records.
    How do I cycle though line per line? (Thinking of a For next loop and getting a new recordset for each recordset to process ?)

  2. #2
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    I doubt you really need to loop through, just employ some better logic to achieve the end goal. I suspect joining to a table with the updates and criteria would mean doing it all in one hit?

    Can you give us some examples of the field value and what you need to update things to.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Could you not use an Update query or two with criteria
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    JB510's Avatar
    JB510 is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Ontario
    Posts
    42
    Quote Originally Posted by Bob Fitz View Post
    Could you not use an Update query or two with criteria
    It can really not be done any other way. (Update query or the like)
    Currently I am updating an old 1993 parts and sales database to the latest version of Access and trying to sort out the records in a newly structured database.
    I have to update Qtys notes Repairs etc so it must be handled line by line as the old database was not structured properly before.
    The new database is structured differently.

    I am currently looping the Auto number with a for next loop and if the Dlookup on the Auto number is blank then I skip the line but it is taking far too long.
    I would rather move line to line eliminating alot of Dlookups that are not necessary.

    With a RecordCount, I was hoping there was a way of doing something like a SQL query to grab one record, process it, then clear all and loop through to the next recordcount record (without grabbing all records at once).

  5. #5
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    I'm not convinced you can't create a joined lookup table however if you want to pursue the looped route;

    The autonumber, although not continuous, will be unique.
    Simply create a temporary table that is based on a sorted order of the autonumbers with it's own new Autonumber, something like
    MyNewIDField MyExistingAutonumber
    1 2
    2 4
    3 7
    4 8

    Now you can create a loop to retrieve each successive original ID based on simply stepping through this new table?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    If there is any field in your edited table that identifies a record as having been fixed then you could get by without another table by querying something like
    SELECT TOP 1 Min(AutoNumberField) AS MinOfAutoNumber, FlagField FROM myTable GROUPBY AutoNumberField HAVING FlagField = ???

    where FlagField is the field that indentifies your record as being "fixed". ??? is because I have no idea what value it would have.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    JB510's Avatar
    JB510 is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Ontario
    Posts
    42
    Thanks Minty, I understand now what you mean.
    This would help.
    I'll create a macro with a new field auto incrementing and the second the auto number.
    Use the auto increment to cycle for the auto number and pull the records that way..

    Thanks, why did I not think of that..

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

Similar Threads

  1. Replies: 5
    Last Post: 11-30-2014, 12:46 PM
  2. Search Text instead of number
    By shah1419 in forum Forms
    Replies: 3
    Last Post: 09-25-2013, 09:14 AM
  3. Replies: 16
    Last Post: 06-20-2013, 09:25 AM
  4. Search for Next Available Number
    By Christine Boissoin in forum Queries
    Replies: 5
    Last Post: 10-05-2011, 12:35 PM
  5. Making New Record Number Next Numerical Number
    By jhillbrown in forum Access
    Replies: 1
    Last Post: 03-10-2010, 11:06 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