473,414 Members | 1,618 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,414 software developers and data experts.

Access Autonumber Problem

26
I have a problem with autonumbering in a database. It relates specifically to the use of the GoToRecord...acnewrec method.

When clicking a button with this method (to add a new record) the autonumber field is incremented by 2 as opposed to 1.

It is however fine when i add a new record via opening the table and clicking on then next free row.

Thanks in advance guys.

Chris.
Dec 17 '07 #1
8 2146
NeoPa
32,556 Expert Mod 16PB
Perhaps you're already at the new record when you say goto new record. This might explain it. Try the following to see if it helps :
Expand|Select|Wrap|Line Numbers
  1. If Not Me.NewRecord Then Call DoCmd.RunCommand(acCmdRecordsGoToNew)
Dec 17 '07 #2
missinglinq
3,532 Expert 2GB
The really important question here is why do you care? Autonumbers are intended to be used by Access for internal housekeeping tasks and really should be never available to users. John Vinson, MVP, posted this a while back:

“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.”

If you need an account number, invoice number, ID number, etc, you need to implement an auto-incrementing number scheme, not use an Autonumber.

Welcome to TheScripts!

Linq ;0)>
Dec 17 '07 #3
NeoPa
32,556 Expert Mod 16PB
That's very well put Linq (and I agree 100%).
I wasn't going to lay this on the OP as so many newbs to database concepts find it very confusing, but it's a good point well made.
Dec 17 '07 #4
cbellew
26
Replies greatly appreciated guys!

Linq - Good explanation, a point well made. I agree. It doesnt matter what number is assigned by autonumber. I guess i did not really explain the problem fully enough:

The problem i have occurs when i add a new record on a main form, which has a subform linked to it (by a one-to-one relationship). Both forms have the same record source For clarity, the main form shows the hospital employee and the subform shows their disease immunity information. I chose to have a subform because of the need for a large amount of controls, which would otherwise not be allowed by a single form.

The problem is that when i add a new employee on the main form, two records are created (lets say for instance records 'A' and 'B'), instead of the normal 'one'. Typically, the details i enter on the main form will be placed into record B and the immunity details on the subform will be placed into record A. I would like the details from both forms to be placed in the same record, ie one record per employee.

The symptom i had described in my first post (whereby the autonumber of each new employee is incremented by 2) is observed when viewing the main form. The field on this form showing the autonumber would display the number assigned to record B.

This is a recent problem and has not always been occuring. Any help would, as always, be greatly appreciated. Thanks. Chris.
Dec 18 '07 #5
missinglinq
3,532 Expert 2GB
It wasn't that you didn't explain your problem fully enough, but rather that you didn't explain it at all! Your problem has nothing to do with autonumbers. Having form and subform share a recordsource is the cause of your problem and simply shouldn't be done; your current problem is just beginning, I'm afraid, if you contimue to follow this course of action. When real estate is an issue, i.e. when the form is crowded with controls, the answer is to use tabbed pages. Tabbed pages not only allow you elbow room on you form, but allow you to divide your information in logical groups. In your situation, for instance, one page could hold employees ID/contact data, another could hold educational/training data, and another the employees immunization info.

If you really have a large amount of data and want to do this with subforms, you need to have separate tables for each of the categories above, linked by a common key field, not one common table.

If you decide to use tabbed pages, here's a HowTo Article with some of the salient points.

Linq ;0)>
Dec 18 '07 #6
cbellew
26
Very helpful again! Sorry not to explain it to start with...confusing i can see!

I like the idea of subforms on a form so im going to stick with that. I have managed to separate my large table into 4 smaller tables all linked by a one-to-one relationships.

I now have EmployeeDetails, MRSADetails, DiseaseHistory and NeedleStick.

The common field is the ID autonumber field used in the initial table, changing three of the four new tables with this column as data type 'number'. They appear to link together ok with 'referential integrity', 'cascade update' and 'cacade delete' all enabled.

I have made a form bound to EmployeeDetails and have included the other three as subforms. The subforms appear to link to the main form and show correct information, but when i add a new record i get the error message:

'Index or primary key cannot contain a Null value'

Any ideas what i have done wrong in my table linking? Once again, thank you!!
Dec 18 '07 #7
NeoPa
32,556 Expert Mod 16PB
I can't help with this I'm afraid, but assuming Linq comes back to answer, I expect he would find your current linking information of your form and subforms quite helpful. It's hard to point out the problem if it's not shown.
Please consider this as helpful guidance rather than criticism. I just know what it's like from the other side of the fence ;)
Dec 18 '07 #8
cbellew
26
Ok, sure, thanks anyway!

I have a main form titled 'Data Entry Form' with EmployeeDetails as the record source. Inside this form i have three subforms; 'Diseases subform', 'MRSA Subform and 'Needle Stick subform' with respective record sources; DiseaseHistory, MRSADetails and NeedleStick. These three tables are all linked to the EmployeeDetails table via one-to-one relationships (for several reasons). They all have the 'ID' field which is the unique primary key for each table, and as such use this field in the relationships.

The subforms 'Link Child Fields' and 'Link Master Fields' properties are both set to 'ID'.

I hope this is adequate information, any suggestions at all would help me alot.

Thanks again guys! Chris.
Dec 18 '07 #9

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

Similar topics

0
by: Frances | last post by:
Hi All, I'm having a problem trying to add a record to a simple Access 2000 db (db is very similar to an address book but with more info than the usual address, phone, etc.). The database is...
1
by: Smriti Dev | last post by:
Hi, I have a question regarding autonumbering . I'm using linked tables between msql and MS Access. Quite a few linked tables exist with relationships. The auto increment fields once linked...
3
by: Mike | last post by:
Using MS Access XP standard install (no Jet or MDAC updates applied yet) as front end, MySQL 4.0 as backend and MySQL ODBC connector version 3.51. When pasting multiple records into the database...
1
by: Knut B. | last post by:
I have a problem with a database of concerts, where I recently tried to change the existing database with some new rows/categories and some new names on a few of the existing ones. I have an id...
6
by: HS1 | last post by:
Hello I have a table in Access Database. This table has a AutoNumber field. I use a DataGrid to show that table When I insert a new record in for this table using a DataGrid, there is a...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
2
by: Hiyella2 | last post by:
Hello, I have a problem with a table in my MS Access 2003 table. The primary key of this table is an autonumber field set to a Long Integer, Yes - no duplicates. The autonumber made it to 10252....
4
by: keri | last post by:
Hello again, While I try and solve the calender issue I also have another problem. I have a form & table (appointments) where the user records appointments in the future. The fields include...
6
by: ashes | last post by:
Hi, I am creating an ecommerce website using Microsoft Visual Studio, VB.Net and MS Access 2003. I am new to VB.Net When someone wants to register on the website, they fill out a form and the...
3
by: limperger | last post by:
Hello! This is quite important. We have an Access file shared in a network. Every user has its front-end copy that is linked to a back-end copy. This database has an autonumber field to count...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.