Simon Foster
Simon Foster

Reputation: 656

Forcing data entry in order

I have a sql server database with ms access frontend.

I want to force data to be entered in a particular table in order.

eg I can only enter id = 2 after id = 1 has been added and I can only add id = 3 after 2 and 1 have been added.

What is the best way to enforce this? Do I need a restriction added to the access frontend or do I need to add a trigger or similar to the sql table?

Upvotes: 0

Views: 84

Answers (2)

user2290627
user2290627

Reputation:

i agree with @Vamsi Pamula, You can do that. But, however if you want to do only what your are looking for then :

First of all, When user tries to enter an new record, track the New ID Given Suppose 10 for now. And, first Query in the database for the Max id before like :

Select isnull(Max(id),0) from YourTable

Suppose the above query returned 8. So, 10 should not be allowed. Now now check :

if (ReturnedValuefromAboveQry + 1 = NEWID) then
    msgbox "Allowed."
else
    msgbox "Not Allowed."
End If

Upvotes: 1

Vamsi Pamula
Vamsi Pamula

Reputation: 147

If you want to do so, keep that id as primary key and set it property as identity (auto increment). You no need to insert that value. Insert the remaining columns and that id will be automatically saved as 1,2 and so on

Upvotes: 0

Related Questions