Results 1 to 6 of 6
  1. #1
    togo is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    83

    Access won't set the first index to 1

    This is a frustrating one.



    Code:
    Set db3 = CurrentDb
    Set db4 = db3.OpenRecordset("ItemAcceptance")
    Set fldColumns = db4.Fields
    curRec = 1
    db4.MoveFirst
    
    While Not db4.EOF
    For Each fldEnumerator In db4.Fields
    If fldEnumerator.Name = "ID" Then
                        db4.Edit: fldEnumerator.Value = curRec: db4.Update
                        curRec = curRec + 1
    End If
    
    // various other routines //
    
    db4.MoveNext
    Wend
    I want the first entry to have an index of 1, each entry following that to increment by one. It will increment by one but gives some other number to the first entry. I tried this

    Code:
    ALTER TABLE temptextdelimit ALTER COLUMN ID COUNTER(1,1)
    query, which doesn't work at all. Thanks for looking at this problem.

    edit: so at the moment, the ID starts at 6463. If there is any way to change this back to 1 that would be great. The order of these items is critical at this stage of the d-base.

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    Is this a case of having built the db and then deleted all the records. So now the db is empty and you are starting to enter new records? If this is the situation. Make sure the db is empty of records and do a compact and repair. See if this returns the count to start at 1.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What are the declarations"?

    Dim db3 as ???
    Dim db4 as ???
    Dim fldColumns as ???
    Dim curRec as ???


    It looks like you are trying to renumber a group of records. If that is the case, try this (on a copy of your database):

    Code:
       Dim db3 As DAO.Database
       Dim rst As DAO.Recordset
       Dim curRec As Long
    
       curRec = 1
       Set db3 = CurrentDb
       Set rst = db3.OpenRecordset("ItemAcceptance")
    
       rst.MoveFirst
    
       While Not rst.EOF
    
          rst.Edit
          rst("ID") = curRec
          rst.Update
          curRec = curRec + 1
    
    
          '// various other routines //
    
          rst.MoveNext
       Wend
    Note: The field "ID" cannot be an "Autonumber" type field....

  4. #4
    togo is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    83
    can't close/reopen/compact database, since this isn't a one time thing. A CSV file is imported through a spec, one of those fields being autonumbered. Then an append query is used to put it into item accepted table as noted above. Declarations have been made in code as suggested in the last post, but were omitted in my post. I will change the spec from autonumber to number and hopefully that will force it to number my way.

    then again it isn't an autonumber in the itemacceptance table.

  5. #5
    togo is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    83
    so nobody really knows why it does this?

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    change the spec from autonumber to number and hopefully that will force it to number my way.
    If the field is a long integer (or a number type), you can number any way you want. An autonumber type is controlled by access.

    then again it isn't an autonumber in the itemacceptance table.
    Don't know what this is: "itemacceptance table"

    Would you care to post your database? It might be easier to understand your problem.

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

Similar Threads

  1. Replies: 1
    Last Post: 09-30-2012, 07:03 AM
  2. Replies: 0
    Last Post: 05-10-2012, 01:25 PM
  3. Choose match index in access
    By dastr in forum Access
    Replies: 1
    Last Post: 03-19-2012, 03:36 PM
  4. 'Id' is not an index in this table - Help
    By waldock9 in forum Access
    Replies: 3
    Last Post: 11-08-2011, 01:48 PM
  5. Access 2010 - Tab Index problem
    By ldare2000 in forum Forms
    Replies: 2
    Last Post: 09-07-2011, 05:26 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