Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    Glad to help. I hope it serves its purpose well.

  2. #17
    davehappen is offline Novice
    Windows 10 Office 365
    Join Date
    Feb 2021
    Posts
    8
    davegri, how can i reset the primary key?????? please

  3. #18
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    Dave is probably asleep right now

    I use this for when I want to reset the Autonumber field after testing. However the experts say there is no real need as it should not matter what the value is, just that it is linked correctly.?
    Code:
    Sub ResetTableNumber(pstrTable As String, pstrID As String)
    Dim strCmd As String, strSQL As String
    strSQL = "DELETE * FROM " & pstrTable
    strCmd = "ALTER TABLE " & pstrTable & " ALTER COLUMN " & pstrID & " COUNTER(1,1)"
    CurrentDb.Execute strSQL
    CurrentDb.Execute strCmd
    End Sub
    NOTE the DELETE command !!!

    Other ways are here https://docs.microsoft.com/en-us/office/troubleshoot/access/reset-autonumber-value
    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

  4. #19
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    As gasman has mentioned, this seldom needs be done. Why do you want to reset the primary key?

    Be advised that gasman's code will DELETE all data in the table.

  5. #20
    davehappen is offline Novice
    Windows 10 Office 365
    Join Date
    Feb 2021
    Posts
    8
    Hi gasman & davegri, I got the point, sorry just me being anal, (A place for everything & everything has a place).
    Many thanks Again

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 08-31-2019, 09:15 AM
  2. Replies: 4
    Last Post: 09-13-2017, 06:19 AM
  3. Replies: 2
    Last Post: 03-30-2015, 12:38 PM
  4. Replies: 1
    Last Post: 08-25-2012, 06:11 PM
  5. Replies: 10
    Last Post: 07-12-2011, 11:09 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