473,789 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Autonumber problem

Hi all,

Here's my situation:

I have 2 tables, let's call them TableA and TableB. TableA has a primary key
called AffNo, TableB's primary key (--> foreign key in TableA) is called ID,
and is Autonumber.
I want to do a form to input information for TableA, with a subform for
TableB where i can enter several records concerning TableA. This seems to
work, however, whenever i click on the 1st Field in the TableB subform, it
generates my Autonumber, but it also generates the record n+1, with empty
fields with exception of Autonumber, wich then has the same number in it as
the record n. This of course triggers a relationship problem because of the
uniqueness of TableB's primary key.

I would be grateful for any suggestions concerning this problem

Thank you,
Ralph Birden
Nov 12 '05 #1
3 1960
> I have 2 tables, let's call them TableA and TableB. TableA has a primary
key
called AffNo, TableB's primary key (--> foreign key in TableA) is called ID, and is Autonumber.


My understanding of this would be that: -.

If TableA has a one to many relationship with TableB then the primary key
from TableA (AffNo) should be a foreign key in TableB.
The problems you mention would then not exist,

Cheers,
Peter

Nov 12 '05 #2
Hi Peter,

That is right, but TableB has a one-to-many with TableA, that's why TableB
primary becomes foreign in TableA

Ralph Birden

"Peter Hoyle" <pe*********@nt lworld-NOT.com> wrote in message
news:OR0qc.1200 5$7S2.4595@news fe1-win...
I have 2 tables, let's call them TableA and TableB. TableA has a primary

key
called AffNo, TableB's primary key (--> foreign key in TableA) is called

ID,
and is Autonumber.


My understanding of this would be that: -.

If TableA has a one to many relationship with TableB then the primary key
from TableA (AffNo) should be a foreign key in TableB.
The problems you mention would then not exist,

Cheers,
Peter

Nov 12 '05 #3
Ralph, I'm a bit confused here.

If you use the primary key of tableB as a foreign key to tableA, you cannot
have a one-to-many relationship between TableA and TableB. Since TableB.ID
is unqiue, you cannot have a 2nd record with the same number and therefore
you cannot have many related records in TableB.

Keep ID (the autonumber) as the primary key in TableB, but add another field
to be the foreign key.
Give it a Data Type of Number.
In the lower pane, leave the Field Size as Long Integer
Delete the zero from the Default Value property.
Set the Required property to Yes.
Save.
Now open the relationship window (Tools menu), and create a relationship
between this new field and TableA.AffNo.

Open your main form in design view.
Right-click the edge of the subform control, and choose Properties.
Beside the LinkChildFields property (Data tab of the Properties box), enter
the name of your new field.

Access will now fill in this value for you automatically whenever you enter
a new value in the subform (assuming the main form is not at a new record).

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Ralph Birden" <ra**********@s mc.etat.lu> wrote in message
news:40******** @news.vo.lu...

Here's my situation:

I have 2 tables, let's call them TableA and TableB. TableA has a primary key called AffNo, TableB's primary key (--> foreign key in TableA) is called ID, and is Autonumber.
I want to do a form to input information for TableA, with a subform for
TableB where i can enter several records concerning TableA. This seems to
work, however, whenever i click on the 1st Field in the TableB subform, it
generates my Autonumber, but it also generates the record n+1, with empty
fields with exception of Autonumber, wich then has the same number in it as the record n. This of course triggers a relationship problem because of the uniqueness of TableB's primary key.

I would be grateful for any suggestions concerning this problem

Thank you,
Ralph Birden

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
4322
by: Lee C. | last post by:
I'm finding this to be extremely difficult to set up. I understand that Access won't manage the primary key and the cascade updates for a table. Fine. I tried changing the PK type to number and setting default value to a UDF that manages the auto-numbering. Access won't take a UDF as a default value. Okay, I'll use SQL WITHOUT any aggregate functions, for the default value. Access won't do that either. Okay, I create a second...
35
7278
by: Traci | last post by:
If I have a table with an autonumber primary key and 100 records and I delete the last 50 records, the next record added would have a primary key of 101. Is there any way to have the primary key start at 51 after the last 50 records are deleted? Thanks! Traci
26
3821
by: jimfortune | last post by:
Sometimes I use Autonumber fields for ID fields. Furthermore, sometimes I use those same fields in orderdetail type tables. So it's important in that case that once an autonumber key value is assigned to a record that it doesn't change. Occasionally I find that due to corruption or an accidental deletion and restore of a record from a backup the autonumber field needs to be tidied up. So when I create (through AddNew) the autonumber...
4
7749
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query, but I can't update record in query or in form. I believe the problem is due to the source query. In source query, there is a filter to show the incomplete record ("is null" in delivery date)], but I need to re-use the job no. if the job is...
11
4498
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 AutoNumber* fields in them. Correct me if I'm wrong, but I'm assuming this means that I cannot now alter these existing Access tables and change their primary key to an "AutoNumber" type. If I'm right about this, I need some suggestions as to the...
2
2830
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. Now when I try to add a new record the autonumber started over at 1. Therefore I am getting an error message saying that it can't save this new record because it contains duplicate values. My best guess is that I need to reset the autonumber...
1
3959
by: gtwannabe | last post by:
I'm having a problem with a form that uses AutoNumber as the primary key. I have an Abort button to delete the current record and close the form. If AutoNumber is assigned, the code executes a SQL statement that deletes the current record. I need to be able to detect when AutoNumber is unassigned (a new blank record) so that I can simply close the form without running the SQL delete statement. Unfortunately, no tests I can think of...
9
11233
by: Tom_F | last post by:
To comp.databases.ms-access -- I just discovered, to my more than mild dismay, that some tables in my Microsoft Access 2003 database have duplicate numbers in the "AutoNumber" field. (Field Size is set to "Long Integer", and New Values is set to "Increment".) I know that an old version of the Jet database engine can cause this problem, but my version of msjet40.dll is 4.0.8618.0, which is supposedly bug-free in this respect. I am...
1
1981
by: OxfordConsult | last post by:
Hello, I have created a form that links with a table with the autonumber feature as its primary key. Whenever i create a new record in the form (using a command button ... i have disabled the navigation buttons) it creates a duplicate primary key value. i.e. it always starts back at 30. If i go to the table it is temperamental. Sometimes it will create a new record with the next autonumber in the sequence, and the next time it resets to...
0
9663
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10136
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.