473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Select a STARTING Primary Key

19
Hello Again Byters (hmmm... that sounded better in my head!)!

Question on Primary Keys / Auto numbering.

I want to make sure that each record has its own individual ID (hence primary key) but, I just want to choose the starting point. So, instead of starting with record ID 1, I'd like to start with record ID 1024. (I'm replacing a paper system with an electronic one, but would like to keep going from where I left off).

So, ideally I would like the next record to automatically be record ID 1025.

I'd like to use this number as my primary key to ensure that I have no duplicates in the future from my starting point forward.

HELP! and Thanks!

best,
Oct 7 '08 #1
7 4676
DonRayner
489 Expert 256MB
Create another table with one field set to a number (not autonumber) with the same name as the autonumber field in your origional table. Put one record in the table with number 1023.

Create an append query using the query builder and use it to append the recrod from your new table to the origional table. It will place 1023 into the autonumber field.

You can delete the new record but the table will keep this value as the last value entered and will then start numbering from 1024.
Oct 7 '08 #2
PaulaCM
19
Create another table with one field set to a number (not autonumber) with the same name as the autonumber field in your origional table. Put one record in the table with number 1023.

Create an append query using the query builder and use it to append the recrod from your new table to the origional table. It will place 1023 into the autonumber field.

You can delete the new record but the table will keep this value as the last value entered and will then start numbering from 1024.

Sorry, could you give me more step by step instructions? I don't understand how to do this. It sounds like it's simple, but I'm an access beginnger (it's 2007 btw, dont' know if that makes a difference).

thanks!
Oct 7 '08 #3
missinglinq
3,532 Expert 2GB
Autonumbers are intended to be used for one purpose and only one purpose, to provide a unique identifier for each record. Here's a post I've archived from a gentleman named John Vinson, MVP, explaining how autonumbers work:

When using Autonumber, do be aware that there will be gaps in the numbering - any record that's deleted will leave a gap; hitting <Esc> after starting a record will leave a gap; adding records using an Append query may leave a gap, often a huge one; replicating the database will make your invoice numbers random.

In short... it's best NOT to use Autonumbers for human consumption, and particularly not for consumption by accountants and auditors. Invoice sequences like 319, 321, 322, 385, 386, 221841246, -1083225152 make such people get very nervous
For the kind of field you're using, you might want to consider using an auto-incrementing number instead, using a hack such as one of these.

The first code here would be for an IDNumber that is defined in the table as Text datatype. "Number" fields that aren't used for math really should be defined as Text.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If Me.NewRecord Then
  3.   If RecordsetClone.RecordCount = 0 Then
  4.    Me.IDNumber = "1024"
  5.   Else
  6.    Me.IDNumber = DMax("val([IDNumber])", "YourTableName") + 1
  7.   End If
  8. End If
  9. End Sub 
If you want to use a Numerical field:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If Me.NewRecord Then
  3.   If RecordsetClone.RecordCount = 0 Then
  4.    Me.IDNumber = 1024
  5.   Else
  6.    Me.IDNumber = DMax("[IDNum]", "YourTableName") + 1
  7.   End If
  8. End If
  9. End Sub
  10.  
Linq ;0)>
Oct 7 '08 #4
ADezii
8,834 Expert 8TB
I could show you code that will automatically set an AutoNumber/Primary Key Field to the Value you specify, but it would be a little complex. The good news is that you would not have to understand it, but only know how to Call the Function, which is very simple. If you are interested, let me know, I'll just need your Table Name as well as the Name of the AutoNumber/Primary Key Field, which, if I remember correctly is Record ID.

P.S. - Missinglinq and DanRayner gave you some good advice, take and learn from it.
Oct 7 '08 #5
mshmyob
904 Expert 512MB
Linq is 100% correct. Sounds like in your situation you should NOT be using an AUTONUMBER data type. Autonumber data types should only be used if the user never needs to reference the PK. Since it appears your PK is based on a number that is critical to the envoronment and is used for specific end user/reporting purposes then DO NOT use an autonumber data type.

As linq says just create a Number data type field and increment that with code.

cheers,
Oct 7 '08 #6
PaulaCM
19
Thanks everyone!

I'm definitely going to keep my primary key an auto number and try to impliment missinglinq's code. Although, i'm a little slow, not having done expressions of any kind before.

So, I'll be back if I can't figure out how to use your awesome code!

thank you again!
Oct 7 '08 #7
PaulaCM
19
Okay. I'm slower than I thought.

would you mind explaining step by step how to incorporate your excellent code into my table?

thanks!
Oct 8 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Will Potter | last post by:
I just inherited support of this app so bear with me. The scenario: Oracle 9i replicated databases, same C++ server process runs on both boxes. On a 15 minute schedule, the server that is primary...
0
by: rg | last post by:
Hello, I use invisionboard on a bid web site (20 000 visitors each day) But my server has high load average. Could you help me to optimize these select command. 1) SELECT p.*,...
0
by: Anthony Altieri | last post by:
Here is the table in question. Number of records 5512825 not a big table and plenty of good indexs i think? that is the big questions. Could some one help? After the table creation and index you...
0
by: Susan Bricker | last post by:
The following error: "The current field must match the join key '?' in the table that seves as t the 'one' side of one-to-many relationship. Enter a record in the 'one' side table with the...
1
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into...
3
by: stefaan.lhermitte | last post by:
Dear MySQL-ians, I perform a SELECT on my database, but it takes over a minute for every run. I have to run it over 10000 times (with different values in the WHERE), so it takes way too long. A...
6
by: jazpar | last post by:
Could anyone help med with a select statement with a join between to tables. It is to be used in a OLAP cube. I Havde table LedgerBudget and Table Admin. In table admin I can setup a from and to...
48
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) *...
7
by: Brian | last post by:
I'm trying to run a select max() on a primary key/unique/non-identity column then + 1, all while running an insert into.. select statement. For some reason, the select max isn't quite doing the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.