Solved

Access SQL autonumber update problem

Posted on 2011-09-20
7
328 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
ID: 36565905
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
ID: 36566330
0
 

Author Comment

by:HKFuey
ID: 36567406
Hi mbizup,
Identity is set to yes. I did a restore anyway as I suspected corruption. Users only lost 3/4 hours work.
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 36567713
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
ID: 36567732
Hi dqmg,
The internal key number links to other tables, will this break the link?
0
 
LVL 42

Expert Comment

by:dqmq
ID: 36568037
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
ID: 36569660
Thanks dqmq, I got it to work, but I also changed my data so not sure what did it!!
Happy anyway : )
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

856 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