Solved

Access SQL autonumber update problem

Posted on 2011-09-20
7
302 Views
Last Modified: 2012-06-21
I have a SQL 2000 database with an autonumber as the key field (intNewIntkey), I restored the database to a test system and ran this code: -
    Do Until rst.BOF Or rst.EOF = True
        With rsItem
            .AddNew
            ![ContractNumber] = rst!ContractNumber
            ![Description] = rst!Description
            .update
            .Bookmark = .LastModified
            intNewIntkey = ![InternalKeyNumber]
        End With

I ran this on the test and imported 300 items no problem, on the live it fails as the InternalKeyNumber is null (error 3022), can anyone help?
0
Comment
Question by:HKFuey
7 Comments
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
Double check the column Identity Specification property for InternalKeyNumber in your SQL back end.

Is Identity should be set to YES.
0
 
LVL 9

Expert Comment

by:sachinpatil10d
Comment Utility
0
 

Author Comment

by:HKFuey
Comment Utility
Hi mbizup,
Identity is set to yes. I did a restore anyway as I suspected corruption. Users only lost 3/4 hours work.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
Comment Utility
Assuming your identity is incrementing, do this from the SQL prompt:

SELECT MAX([InternalKeyNumber]) FROM yourtable

DBCC CHECKIDENT ('yourtable', RESEED, #######)


For ###### substitute the number returned from the first select.
0
 

Author Comment

by:HKFuey
Comment Utility
Hi dqmg,
The internal key number links to other tables, will this break the link?
0
 
LVL 42

Expert Comment

by:dqmq
Comment Utility
It doesn't update existing rows... just affects rows that are subsequently added.  If the rows being inserted are linked to other tables, then you have a serious matter.
0
 

Author Closing Comment

by:HKFuey
Comment Utility
Thanks dqmq, I got it to work, but I also changed my data so not sure what did it!!
Happy anyway : )
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now