473,407 Members | 2,629 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,407 software developers and data experts.

Auto Generated Field with Specified Format and Acting as Primary Key

Hello everyone,

If anyone could help me with this little dilemma, it would be greatly appreciated. Here is the scenario: I would like to generate a field called "PO" (which would be the primary key) that has the following fixed format (L-0000-00000)

ei. M-3055-00001

where cmbReqType = M; txtJobNumber = 3055 & TypeID = (Automated number)

The first letter is chosen by the user (with a combo box named cmbReqType) in the main form (frmPO). The second part is automatticaly added from txtJobNumber from a different form (constant for all POs). Then, I would like the third part to keep track and increment automatically depending on the ReqType that the user will choose.

ei. if the user chooses ReqType "M", the form will automatically generate the following PO: M-3055-00001

if the user chooses ReqType "M" again, the form will automatically generate the following PO: M-3055-00002

if the user chooses ReqType "S", the form will automatically generate the following PO: S-3055-00001 (Restarting the count for the ReqType "S")

if the user rechooses ReqType "M", the form will automatically generate the following PO: M-3055-00003

and so on and so forth.


After, these PO numbers will be the primary key linking various Cost Codes and Vendors.

For better picture of the hierarchy of the database (Roman letters indicate levels):

i) JobNumber (3055)

ii) PO1 (M-3055-00001)

iii) CostCode (3055.00100.0002) - Vendor (ABC Inc.)
iii) CostCode (3055.00100.0002) - Vendor (123 Inc.)
iii) CostCode (3055.00100.0005) - Vendor (ABC Inc.)

ii) PO2 (M-3055-00002)

iii) CostCode (3055.00100.0003) - Vendor (ABC Inc.)
iii) CostCode (3055.00100.0002) - Vendor (123 Inc.)

ii) PO3 (S-3055-00001)

iii) CostCode (3055.00100.0002) - Vendor (ABC Inc.)
iii) CostCode (3055.00200.0002) - Vendor (123 Inc.)

In word, one JobNumber can have many POs (No Duplicates), one PO can have many same or different CostCode, every PO will be linked to a Vendor and finally, one Vendor can be linked to many POs

All the tables & forms are made, and I am ready to create the relationships between the tables just didn't know how to generate my POs in this specifc from. If there is a way, please help me out.

Sincerely,

Kyle
May 8 '14 #1
1 1257
zmbd
5,501 Expert Mod 4TB
1) It is best practice to NOT use such a method to generate your primary key. The primary key should normally have no other use nor meaning other than to uniquely identify the record.

Why you might ask... I'll give you a for instance:
We used to have "audit" numbers from an AS400 system
The company was bought out, now they have sampleidnumber, ticket numbers, lot number, etc... and our old audit number that used to be unique is now a "ticket number" that is quite often re-used between differing customers and tests; however, my internal database used the autonumber field as the primary key... no harm no foul, I simply changed our "audit" to handle the sampleidnumber.

2) "generate a field called " is actully spot on; however, you would do this on demand within a query.
2a) let us take your fixed format (L-1111-22222)
where cmbReqType = L; txtJobNumber = 1111 & TypeID = (Automated number = 22222)

If you have the fields:[cmbReqType]; [txtJobNumber]; [TypeID]
such
[cmbReqType] = M;
[txtJobNumber] = 3055 &
[TypeID] = (Automated number)
Thn in a calculated field within the query, you could do:
PONum: [cmbReqType] & "-" & [txtJobNumber] & "-" & [TypeID]

3) The trick is this: [TypeID] = (Automated number)

M-3055-00001
M-3055-00002
and then
S-3055-00001 (Restarting the count for the ReqType "S")
and then
M-3055-00003

We query against [cmbReqType] and find max() for the given and add one.

Do you need this?
M-3055-00001
M-3055-00002
M-3055-00003
M-3056-00001
M-3055-00004
M-3055-00005
M-3056-00002
M-3056-00003

Once again easy enough to do, query on[cmbReqType] = M; and then [txtJobNumber]= (the desired) and return the current max in [TypeID] add one to the value.

4) I more than likely would create a single PO table:
tbl_purchaseorder
[purchaseorder_pk] autonumber primary key
[purchaseorder_ReqType]
[purchaseorder_JobNumber]
[purchaseorder_TypeNumber]

Link the [purchaseorder_pk] to your other tables as needed
The fields[purchaseorder_ReqType] and [purchaseorder_JobNumber] might also need to be linked out to your other tables; however, I don't know your database schema

Please refer to:[*]> Database Normalization and Table Structures.

You will find a lot of methods on how to handle this by typing "Access" and either "Lot Numbers" or "serial numbers" into the search box next to the Bytes.Com logo above.
May 8 '14 #2

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

Similar topics

1
by: Ryan Hubbard | last post by:
I'm inserting a record into MySQL 4.0 using Visual Basic ADO. When using the AddNew and Update method I am unable to retrieve the value of a Auto incrment field (Yes I know I can MoveLast but this...
3
by: Poul Møller Hansen | last post by:
Hi, I need an auto incrementing field that will contain values like N000001, N000002, N000003 etc. I think the way is to use the value from an identity field in a stored procedure that is...
2
by: Irwinsp | last post by:
Hi All, I have a form with an auto number field displayed. The field looks great except when the user is entering a new record. The field then has the text "auto number" in it. Is there a...
0
by: Viorel | last post by:
Working as a beginner with data objects in Visual Studio 2003 and C#, I use the "Generate Dataset" command in order to generate automatically the dataset objects based on data adapters. Generated...
4
by: MUSTAFA IRSHAD | last post by:
DEAR SIRS, I AM DEVELOPING A SOFTWARE BY USING VB.NET AND SQLSERVER 2000 FOR A NETWORK ENVIRONMENT. I HAVE A BROBLEM THAT I HAVE A FIELD FOR PRIMERY KEY WHICH IS AUTO GENERATED. I NEED THAT WHEN...
6
by: | last post by:
Hi, can someone provide some advise on how to get around with using auto generated proxies? basically I already have the proxy classes, and they are used by other places. I'd like use these...
9
by: danielbuus | last post by:
Hey there :) I'm using Ruby on Rails to create a migration of a legacy database on an MS SQL Server. I'd like to name my constraints myself, such as 'pk_authors', but in the cases where a table...
2
by: pratitripathi | last post by:
Hi , I'm having problem in generating auto generated Code whose format is 'PRM-0000' .And it should be incremented by one everytime when new Id is generated.the value will be stored in database. ...
9
zimes
by: zimes | last post by:
I am working with Microsoft Access 2003 from the Office XP pro suite. I have created several tables that have to do with Asset tracking along with purchasing. I have a table called Purchasing,...
1
by: azai lestary | last post by:
I need you help please.... first I want to create a page for php.. Inside it, I can add a number in a textfield... Then, textfield for 'name' will be generated based on that number... for...
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
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
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
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.