A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

"Multiple Autonumber" in same table



 
 
Thread Tools Display Modes
  #1  
Old April 13th, 2009, 10:07 AM posted to microsoft.public.access.tablesdbdesign
Mat Child
external usenet poster
 
Posts: 14
Default "Multiple Autonumber" in same table

Hi,
I'm trying to find out if there is a way of creating an autonumber like
feature on related records in a table, but there can be multiple instances of
the same number. It's down to Parent Child records - I'll explain

Parent Table (RT) Child Table (Slots)
PK - RT_id (autonumber) PK - SLOT_id (autonumber)
[other fields] SLOT_RT_id (foreign key
link to parent)
SLOT_Number (Long
Integer)
[other fields]

The retionship is one to many with referential integrity cascading updated
and deleted records.
What i would like to do is force the field SLOT_Number to be unique from 1
to whatever, but only within the records relating back to the parent record.
This means there will be duplicated values within this field in the table but
not when you take into account the foreign key.

An ideas would be greatly appreciated.

Thanks

Mat

  #2  
Old April 13th, 2009, 10:23 AM posted to microsoft.public.access.tablesdbdesign
Stefan Hoffmann
external usenet poster
 
Posts: 991
Default "Multiple Autonumber" in same table

hi Mat,

Mat Child wrote:
What i would like to do is force the field SLOT_Number to be unique from 1
to whatever, but only within the records relating back to the parent record.
This means there will be duplicated values within this field in the table but
not when you take into account the foreign key.

You can do this by using

Nz(DMax("SLOT_Number", "Slots", "SLOT_RT_id = " & [idParent]), 0) + 1

in either a query or in a Form Before Insert event.

btw, you need at least an unique index on (SLOT_RT_id, SLOT_Number). You
may consider using these two fields as primary key depending on your
further usage of the Slots table.


mfG
-- stefan --
  #3  
Old April 13th, 2009, 12:06 PM posted to microsoft.public.access.tablesdbdesign
Mat Child
external usenet poster
 
Posts: 14
Default "Multiple Autonumber" in same table

Brill,

It worked a treat, cheers for that.


"Stefan Hoffmann" wrote:

hi Mat,

Mat Child wrote:
What i would like to do is force the field SLOT_Number to be unique from 1
to whatever, but only within the records relating back to the parent record.
This means there will be duplicated values within this field in the table but
not when you take into account the foreign key.

You can do this by using

Nz(DMax("SLOT_Number", "Slots", "SLOT_RT_id = " & [idParent]), 0) + 1

in either a query or in a Form Before Insert event.

btw, you need at least an unique index on (SLOT_RT_id, SLOT_Number). You
may consider using these two fields as primary key depending on your
further usage of the Slots table.


mfG
-- stefan --

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:31 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.